java - 如何使用selenium点击附加html上的按钮?

标签 java html selenium

<div class="dropdown-div u-space-ls u-inline-block" data- 
reactid=".0.0.0.3.1"><a class="dropdown-div__button js-dropdown button" 
href="#" data-reactid=".0.0.0.3.1.0"><span class="u-pad-rs" data- 
reactid=".0.0.0.3.1.0.0">ACTIONS</span><span class="icon icon-caret-down" 
data-reactid=".0.0.0.3.1.0.1"></span></a><ul class="js-actions-dropdown- 
menu" data-reactid=".0.0.0.3.1.1"><li class="js-save-button" data-tooltip=" 
{&quot;placement&quot;:&quot;bottom&quot;,&quot;title&quot;:&quot;Save the 
current layout and filters as the default setting, or as a new 
report.&quot;}" data-reactid=".0.0.0.3.1.1.0"><span class="icon icon-files-o 
u-space-rs" data-reactid=".0.0.0.3.1.1.0.0"></span><span data- 
reactid=".0.0.0.3.1.1.0.1">Save Layout</span></li><li class="js-email- 
button" data-reactid=".0.0.0.3.1.1.1"><span class="icon icon-envelope-o u- 
space-rs" data-reactid=".0.0.0.3.1.1.1.0"></span><span data- 
reactid=".0.0.0.3.1.1.1.1">Email…</span></li><li data- 
reactid=".0.0.0.3.1.1.2"><span class="icon icon-file-excel-o u-space-rs" 
data-reactid=".0.0.0.3.1.1.2.0"></span><span data- 
reactid=".0.0.0.3.1.1.2.1">Export as Excel</span></li><li data- 
reactid=".0.0.0.3.1.1.3"><span class="icon icon-bar-chart u-space-rs" data- 
reactid=".0.0.0.3.1.1.3.0"></span><span data- 
reactid=".0.0.0.3.1.1.3.1">Export as CSV</span></li></ul></div>

我尝试找到“dropdown-div u-space-ls u-inline-block”和“js-actions-dropdown-menu”的xpath和选择器并单击它,但这些选项都不适合我。

Starting ChromeDriver 2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb) 
on port 5073
Only local connections are allowed.
Apr 23, 2018 10:31:44 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element <div class="dropdown-div u-space-ls u-inline-block" data-reactid=".0.0.0.3.0">...</div> is not clickable at point (769, 17). Other element would receive the click: <div class="ReactModal__Overlay ReactModal__Overlay--after-open modal_container__overlay" data-reactid=".1">...</div>
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'DESKTOP-D34PQOQ', ip: '192.168.241.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.38.552522 (437e6fbedfa876..., userDataDir: C:\Users\ALVINZ~1\AppData\L...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 65.0.3325.181, webStorageEnabled: true}
Session ID: 2b96523cc89e3c10d4d8824343d438d5
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
    at reader.main(reader.java:49)

这是程序运行后的控制台。

最佳答案

这应该有效:

By.xpath("//div[@class='dropdown-div u-space-ls u-inline-block']"

或者这个:

By.xpath("//*[@class='js-actions-dropdown- menu']//*[@data-reactid='.0.0.0.3.1.1']")

或者这个:

By.xpath("//*[contains(@class,'dropdown-div')]")

对于选项标签可用时的下拉菜单:

By.xpath("//option[contains(@value,'Export as CSV')]

这里的xpath是双引号“”之间的一个。让我知道这是否有帮助。

关于java - 如何使用selenium点击附加html上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49993797/

相关文章:

java - Struts 2 应用程序在通过管理控制台部署时出错

html - 包装图像在风格上有效但在 img 中无效

html - 悬停同一父级的一个 DIV 时影响多个 DIV

java - 在多行表中查找元素

java - 如何使用 Selenium WebDriver 删除文本字段中的默认值并输入新值

java - 值始终为空

C# 与 Java 枚举(适用于 C# 新手)

javascript - 使用 Angular JS 将焦点设置在选项卡上的 Span 上

maven - 将 Selen 测试与构建过程分开

java - 国际化 - 列出和添加语言