ChromeDriver在页面上找不到具有硒JAVA的元素

问题描述 投票:0回答:1

我正在尝试在页面上找到一个元素,我想对结果列表进行排序,但是我的结果显示页面上未附加该元素:

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=79.0.3945.130)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'mac-etmc.local', ip: 'fe80:0:0:0:8d:ed57:9129:7f9c%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 79.0.3945.130, chrome: {chromedriverVersion: 79.0.3945.36 (3582db32b3389..., userDataDir: /var/folders/n9/345_wf417mz...}, goog:chromeOptions: {debuggerAddress: localhost:62544}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 131de26bb0480d9c39dab037c54e0228
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    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:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:134)
    at TestAmazon.main(TestAmazon.java:49)

这是执行此操作的JAVA代码:

    //Order asc way 1
            WebElement listOrder = driver.findElement(By.id("a-autoid-0"));
            listOrder.click();
//Order asc way 2
WebElement listOrder = driver.findElement(By.xpath("//*[@id=\"a-autoid-0\"]"));
        listOrder.click();

//Order asc way 3
WebElement listOrder = driver.findElement(By.xpath("/html/body/div[1]/div[1]/span/h1/div/div[2]/div/div/span/form/span/span"));
        listOrder.click();

我注意到xtrange的东西,第一张图片中的SPAN没有显示在页面上,只能像容器一样工作,这是问题吗?请帮助我...如何使用ChromeDriver获取此元素?

enter image description here

enter image description here

java selenium xpath automation qa
1个回答
0
投票

尝试一下:

  • CSS选择器:.a-button-text.a-declarative#a-autoid-0-announce
  • XPath://*[@id="a-autoid-0-announce"]
© www.soinside.com 2019 - 2024. All rights reserved.