Selenium WebDriver - 隐藏选择和锚点 [英] Selenium WebDriver - hidden select and anchor

查看:285
本文介绍了Selenium WebDriver - 隐藏选择和锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Selenium WebDriver - 从隐藏选择中获取选项


我在一个页面上选择一个大问题。


代码:

 < select name =fw3k_ad_input_et_type_groupclass = 
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 = - 1class =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_itemid =fs_item_0style => --- odaberite tip ---< / a>



查看:


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



选择被隐藏,并且href =是可见的部分,根据所选的选项更改其文本。



<我真的不知道如何管理。我可以使用JavascriptExecutor获取所有选项,我可以使用a.click()来查看下拉框,但我不知道如何点击某些选项。



我已经尝试使用Select class和.getOptions()方法,但它不适用于隐藏选择,我无法更改href =文本。



:(



请帮助我一些例子。

解决方案

第一种方式: / strong>
它不是单击任何使用相同的js的元素的问题。你知道如何获得任何选项最后的操作是执行一个单击
这应该适用于你: / p>

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

第二种方式

  String cssSelector = ... //我给你的上一个问题
JavascriptExec utor js =(JavascriptExecutor)驱动程序;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(var x = $(\'+ cssSelector +\'););
stringBuilder.append(x.click(););
js.executeScript(stringBuilder.toString());

第三种方式:
使用动作构建器,高级用户操作API。您可以阅读它 here
代码将会像这样:

  WebElement mnuElement; 
WebElement submnuElement;
mnEle = driver.findElement(By.Id(mnEle))。click();
sbEle = driver.findElement(By.Id(sbEle))。click();

Actions builder = new Actions(driver);
//将光标移动到主菜单元素
builder.moveToElement(mnEle).Perform();
//为子菜单提供5秒
Thread.sleep(5000L);
//单击隐藏子菜单
driver.findElement(By.Id(sbEle))。click();

您还可以添加一些附加信息这里
希望这可以帮助你)


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.

解决方案

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)

这篇关于Selenium WebDriver - 隐藏选择和锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆