硒:单击"/div"/a//div.按钮 [英] Selenium: Click on a "<div><a></a></div>" button
本文介绍了硒:单击"/div"/a//div.按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图单击一个按钮.它具有以下结构:
I tried to click on a button. It has this structure:
<div class="button-wrapper" id="button-verify-wrapper">
<a x-ng-click="verifySfdcConnection()" class="clearfix float-left button-green">
<div class="icon-green icon-green-verify"></div>
<div class="button-label ng-binding">Verify Connection</div>
</a>
<div x-ng-class="{'connection-verified':wizardData.inputSource.sfdc.connectionStatus}" x-ng-show="wizardData.inputSource.sfdc.connectionStatus" style="" class="connection-verified"></div>
</div>
任何帮助该怎么做?我试过了:
Any help how to do it? I tried this:
driver.findElement(By.xpath(".//*[@id='button-verify-wrapper']/a/div[1]")).click();
但这没有帮助.谢谢
推荐答案
我认为< a>
元素可在此处单击.您应该尝试定位< a>
元素,然后执行 click()
操作,如下所示:-
I think <a>
element is clickable here. You should try to locate <a>
element instead and perform click()
action as below :-
-
使用
By.cssSelector()
:-
driver.findElement(By.cssSelector("div#button-verify-wrapper > a")).click();
使用 By.linkText()
:-
driver.findElement(By.linkText("Verify Connection")).click();
使用 By.xpath()
:-
driver.findElement(By.xpath(".//a[normalize-space(.) = 'Verify Connection']")).click();
如果仍然无法执行点击,请尝试使用 JavascriptExecutor
作为替代解决方案,如下所示:-
If you're still unable to perform click, try as an alternate solution using JavascriptExecutor
as below :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", driver.findElement(By.cssSelector("div#button-verify-wrapper > a")));
这篇关于硒:单击"/div"/a//div.按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文