本文介绍了点击()对CSS选择器中硒的webdriver不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML

 <输入类=按钮类型=按钮的onclick =$重装('结果')值=搜索>

我没有这一个id或名称。因此,我写

  FirefoxDriver司机=新FirefoxDriver();
driver.get(HTTP:// ...);
。driver.findElement(By.cssSelector(输入[值=搜索]))点击();

但点击()没有发生。

试过
    driver.findElement(By.cssSelector(按钮[值=搜索]。))点击();

试过
    值=搜索(单引号)。

这些选择在工作

  .button [值=搜索] {
填充:10px的;
}
输入[值=搜索] {
填充:10px的;
}


解决方案

我会注入一块JS在解决这个问题上有信心:

首先使用DOM的所有元素定位的(在Firebug验证):

 公共无效jsClick(){        JavascriptExecutor JS =(JavascriptExecutor)驱动程序;
        StringBuilder的StringBuilder的=新的StringBuilder();
        stringBuilder.append(document.getElementsByTagName(按钮)[0]。点击(););
        js.executeScript(stringBuilder.toString());
    }
jsClick();

从元素的追溯它是这样:

  ....
stringBuilder.append(document.getElementsByTagName('输入')[0]。点击(););
....

请,注意: document.getElementsByTagName('输入')返回DOM元素的数组。和索引得当例如document.getElementsByTagName('输入')[0],document.getElementsByTagName('输入') 1 ,document.getElementsByTagName('输入')[2] ....
等你就能找到你的元素。

希望这有助于你。
问候。

HTML

<input class="button" type="button" onclick="$.reload('results')" value="Search">

I don't have an id or name for this . Hence am writing

FirefoxDriver driver = new FirefoxDriver();
driver.get("http://....");
driver.findElement(By.cssSelector("input[value=Search]")).click();

But click() is not happening.

Tried driver.findElement(By.cssSelector(".button[value=Search]")).click();

Tried value='Search' (single quotes).

these Selectors are working in

.button[value=Search] {
padding: 10px;
}
input[value=Search] {
padding: 10px;
}

i would inject piece of js to be confident in resolving this issue:

first of all locate element using DOM (verify in firebug):

public void jsClick(){

        JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("document.getElementsByTagName('button')[0].click();");
        js.executeScript(stringBuilder.toString());
    }
jsClick();

from the retrospective of your element it be like:

....
stringBuilder.append("document.getElementsByTagName('input')[0].click();");
....

Please, note: document.getElementsByTagName('input') returns you an array of DOM elements. And indexing it properly e.g. document.getElementsByTagName('input')[0], document.getElementsByTagName('input')1, document.getElementsByTagName('input')[2]....,etc you will be able to locate your element.

Hope this helps you.Regards.

这篇关于点击()对CSS选择器中硒的webdriver不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 11:02