Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 无法使用无头Selenium浏览器单击按钮_Jquery_Selenium_Headless Browser - Fatal编程技术网

Jquery 无法使用无头Selenium浏览器单击按钮

Jquery 无法使用无头Selenium浏览器单击按钮,jquery,selenium,headless-browser,Jquery,Selenium,Headless Browser,我试图使用一个headless PhantomJSDriver()和一个click()命令单击此页面上的一个按钮,但它挂起了大约半分钟,然后声称找不到元素。如何正确识别按钮并模拟单击它 我的代码片段: driver.findElement(By.xpath("//input[@class='btn btn-primary btn-xs' and @type='button']")) .click(); 错误消息: [ERROR - 2015-07-22T23:01:51.589Z] WebEl

我试图使用一个headless PhantomJSDriver()和一个click()命令单击此页面上的一个按钮,但它挂起了大约半分钟,然后声称找不到元素。如何正确识别按钮并模拟单击它

我的代码片段

driver.findElement(By.xpath("//input[@class='btn btn-primary btn-xs' and @type='button']"))
.click();
错误消息:

[ERROR - 2015-07-22T23:01:51.589Z] WebElementLocator -
_handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1437606111543
<td ng-show="hit.HITStatus == 'Unassigned'" class="col-sm-1">
    <a href="www.theurl.com">
        <button type="button" class="btn btn-primary btn-xs">What the button says</button>
    </a>
</td>
被检查元素:

[ERROR - 2015-07-22T23:01:51.589Z] WebElementLocator -
_handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1437606111543
<td ng-show="hit.HITStatus == 'Unassigned'" class="col-sm-1">
    <a href="www.theurl.com">
        <button type="button" class="btn btn-primary btn-xs">What the button says</button>
    </a>
</td>

看。。。代码

class="btn btn-primary btn-xs"
表示此元素未分配给类“btn btn primary btn xs”,表示此元素分配给3个不同的类:“btn”、“btn primary”btn xs

这意味着您无法通过xpath找到此元素:
“//输入[@class='btn btn primary btn xs'和@type='button']”
因为不存在这样的类=) 您需要将此xpath更改为更正确的:

".//input[@class='btn-xs' and @type='button']"
在这种情况下,它不会找到正确的按钮(我认为它会找到,但不正确)。 您需要在包含一些父元素的情况下构建更好的xpath