Selenium WebDriver - hidden select and anchor [duplicate]

0
0

Possible Duplicate:

Selenium WebDriver – get options from hidden select

I’m having a big problem with select on one page.

Code:

<select name="fw3k_ad_input_et_type_group" class="" 
id="_id_fw3k_ad_input_et_type_group"
onchange=" eurotax.change_type_group( this.value ); "
style="display: none; ">
<option value="0"> --- odaberite tip --- </option>
<option value="-1" class="special">> nema mog tipa </option>
<option value="16390">CD</option>
<option value="17605">S</option>
<option value="17636">SE</option>
</select>
<a href="" class="fs_item" id="fs_item_0" style=""> --- odaberite tip --- </a>

View:

http://imageshack.us/f/7/screenshotfrom201209111.png/

Select is hidden and a href=”” is visible part that changes its text depending on a selected option.

I really dont know how to manage that. I can get all options with JavascriptExecutor and I can use a.click() to view dropdown box but I dont know how to click on some option.

I have tried to use Select class and .getOptions() method but it doesn’t work with hidden select and I cannot change a href=”” text.

🙁

Please help me with some example.

  • You must to post comments
0
0

1st way:
it is not the problem to click any element using the same js. As you know how to get any option the last actions remaning is to perform a click.
This should work for you:

WebElement hiddenWebElement =driver.findElement(By(..selector of the element....));
((JavascriptExecutor)driver).executeScript("arguments[0].click()",hiddenWebElement);

2nd way:

String cssSelector= ...//i gave them in your previous question
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x = $(\'"+cssSelector+"\');");
stringBuilder.append("x.click();");
js.executeScript(stringBuilder.toString());

3rd way:
using actions builder, advanced user actions API. You can read about it here
And code will be smth like that:

WebElement mnuElement;
WebElement submnuElement;
mnEle = driver.findElement(By.Id("mnEle")).click();
sbEle = driver.findElement(By.Id("sbEle")).click();
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnEle).Perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
driver.findElement(By.Id("sbEle")).click();

You can also some additional info here
Hope this somehow helps you)

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website