Can';不能阅读,也不能阅读';t在selenium和Java程序运行中以联机形式输入数据,然后出现以下错误

Can';不能阅读,也不能阅读';t在selenium和Java程序运行中以联机形式输入数据,然后出现以下错误,java,excel,apache,google-chrome,selenium,Java,Excel,Apache,Google Chrome,Selenium,您在这一行中遇到了一个NoTouchElementException:driver.findElement(By.id(“isc\u PickListMenu\u 1\u body\u cell0\u 1”)。单击() 这可能是由几个不同的问题引起的,我在这里要提到两个: 如果这一行总是失败,那么当您的测试到达该点时,很可能没有id为isc\u PickListMenu\u 1\u body\u cell0\u 1的元素 如果随机出现不同的行失败,那么在与它们交互之前,可能需要开始等待元素可用

您在这一行中遇到了一个
NoTouchElementException
driver.findElement(By.id(“isc\u PickListMenu\u 1\u body\u cell0\u 1”)。单击()

这可能是由几个不同的问题引起的,我在这里要提到两个:

  • 如果这一行总是失败,那么当您的测试到达该点时,很可能没有id为
    isc\u PickListMenu\u 1\u body\u cell0\u 1
    的元素

  • 如果随机出现不同的行失败,那么在与它们交互之前,可能需要开始等待元素可用

  • 以下是一种方法:

    Starting ChromeDriver 2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf) on port 44745
    Only local connections are allowed.
    Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"isc_PickListMenu_1_body_cell0_1"}
      (Session info: chrome=55.0.2883.87)
      (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 70 milliseconds
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:55:52'
    System info: host: 'DTCD28244FD19AF', ip: '172.25.82.144', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\U524915\AppData\Local\Temp\scoped_dir11176_19426}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
    Session ID: 8a52a58967ae1d511cc6298c24f4226a
    *** Element info: {Using=id, value=isc_PickListMenu_1_body_cell0_1}
        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:206)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)
        at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:403)
        at org.openqa.selenium.By$ById.findElement(By.java:218)
        at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345)
        at paymenttransfer.PaymentTransfer.main(PaymentTransfer.java:63)
    
    然后您就可以找到元素并使用它了:

    By elemBy = By.id("isc_PickListMenu_1_body_cell0_1")
    (new WebDriverWait(driver, 15)).until(ExpectedConditions.elementToBeClickable(elemBy));
    

    从稳定性的角度来看,这个测试看起来可能做得太多了,这会让我们很难找出哪里出了问题。如果可能的话,我建议让它执行一个小的特定用例。

    我尝试重新格式化这段代码,但它不允许我保存我的更改,因为它只是大量的代码,没有足够的细节。如果可能,请添加一些上下文:)如果只是复制和粘贴,请先缩进。我想它会在几秒钟后运行并停止,请立即尝试。感谢您尝试帮助我。我不确定编辑时代码与文本的比率需要什么堆栈溢出,所以我只需要保留格式:)
    By elemBy = By.id("isc_PickListMenu_1_body_cell0_1")
    (new WebDriverWait(driver, 15)).until(ExpectedConditions.elementToBeClickable(elemBy));
    
    driver.findElement(elemBy).click();