无法在用户名框中执行发送密钥().它显示了使用Selenium Webdriver的Elementnotinteract



在注册表中,尝试使用 sendkeys(( 在用户名文本框中输入文本。但它会抛出 ElementNotInteractable 异常。然后我用隐式等待和webdriverwait来找到那个元素,它也抛出了超时异常。请为此提出解决方案,因为我无法在这里继续。使用Selenium Webdriver与java。

这是使用的网站

附加了 DOM 树图像

代码如下:

@Test
public void regform() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
RemoteWebDriver d = new ChromeDriver();
d.manage().window().maximize();
d.get("http://way2automation.com/way2auto_jquery/index.php");
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(d, 20);
WebElement usrname = d.findElementByXPath("//input[@name='username']");
wait.until(ExpectedConditions.visibilityOf(usrname));
usrname.sendKeys("User1");
d.close();
}

控制台日志:

FAILED: regform
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of [[ChromeDriver: chrome on WINDOWS (12e645803db8e870be7722d06896cc88)] -> xpath: //input[@name='username']] (tried for 20 second(s) with 500 milliseconds interval)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-O0V8JPK', ip: '192.168.1.12', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 81.0.4044.138, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: C:UsersShamiliAppDataLo...}, goog:chromeOptions: {debuggerAddress: localhost:61086}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 12e645803db8e870be7722d06896cc88
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
at basicautomationconcepts.RegistrationForm.regform(RegistrationForm.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

您尝试自动化的页面包含两个类似的表单,因此 DOM 中有两个与您的 XPath 匹配的元素。第一个不显示,因此不可交互。这就是为什么你得到了ElementNotInteractableException,这就是为什么你会TimeoutException试图等到它变得可见。

将 xpath 更改为"(//input[@name='username'])[2]"应该可以解决问题。

您也可以尝试使用以下 xpath。它对我有用。

"//*[@id="load_form"]/fieldset[6]/input"

相关内容

  • 没有找到相关文章

最新更新