gpt4 book ai didi

java - 如何使用 Selenium 和 Java 定位元素

转载 作者:行者123 更新时间:2023-12-02 10:01:26 24 4
gpt4 key购买 nike

我无法识别给定代码中的定位器来执行自动化测试。

元素的 HTML:

<a href="https://www.amazon.in/ap/signin?openid.pape.max_auth_age=0&openid.retu…%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&" class="nav-a nav-a-2" data-nav-ref="nav_ya_signin" data-nav-role="signin" data-ux-jq-mouseenter="true" id="nav-link-accountList" tabindex="25">

错误堆栈跟踪:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='nav-link-accountList']/span[3]"}
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.10 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'LAPTOP-118FCQKH', ip: '192.168.43.44', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\Hp\AppData\Local\Temp\scoped_dir5888_21816}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=73.0.3683.86, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 107d4a42af64419e98016e7927c7dde3
*** Element info: {Using=xpath, value=//*[@id='nav-link-accountList']/span[3]}

最佳答案

有一个 id,因此使用它作为最快的选择器方法

#nav-link-accountList

关于java - 如何使用 Selenium 和 Java 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55596422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com