gpt4 book ai didi

php - 如何通过 Selenium 找到元素

转载 作者:行者123 更新时间:2023-12-03 17:21:47 24 4
gpt4 key购买 nike

我将 Selenium 与 PHP WebDriver 一起使用。我正在尝试单击导航栏中的链接,该链接显示在 HTML 中,如下所示:

<li class=""><a href="javascript:;" showpage="cards"><i class="zzdi zzdi-closed-caption zzdi-hx-fw"></i> User Cards</a></li>

我正在尝试选择元素然后单击它。但是,当我尝试按如下方式使用 xpath 时:
//a[@showpage="cards"]

或者
//*[@showpage="cards"]

我收到以下错误:

no such element: Unable to locate element: {"method":"xpath","selector":"/*[@showpage="cards"]"} (Session info: chrome=70.0.3538.110) (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-43-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 24 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-43-generic', java.version: '1.8.0_191' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=LINUX, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:43431}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d), userDataDir=/tmp/.org.chromium.Chromium.Teyqo7}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, version=70.0.3538.110, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}] Session ID: 367080a50b61c75a8c16a17b954a5972 *** Element info: {Using=xpath, value=/*[@showpage="cards"]}



任何有关如何使用 xpath 或如何使用任何其他使我能够单击链接的选择方法的帮助将不胜感激。

最佳答案

您可能需要等待元素能够单击它:

$driver->wait()->until(
WebDriverExpectedCondition::elementToBeClickable(WebDriverBy::xpath('//a[@showpage="cards"]')))->click();

关于php - 如何通过 Selenium 找到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53894057/

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