您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Selenium WebDriver在线程“ main” org.openqa.selenium.ElementNotInteractableException中引发异常

Selenium WebDriver在线程“ main” org.openqa.selenium.ElementNotInteractableException中引发异常

根据文档, ElementnotinteractableException 是W3C异常,引发该异常以指示尽管DOM Tree上存在一个元素,但该元素处于无法与之交互的状态。

ElementnotinteractableException 发生的原因可能很多。

在这种情况下,直接的解决方案将是,以诱导 ExplicitWaitwebdriverwait 结合ExpectedCondition为 如下:

    webdriverwait wait2 = new webdriverwait(driver, 10);
wait2.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("xpath_of_element_to_be_invisible")));
driver.findElement(By.xpath("xpath_element_to_be_clicked")).click();

一个更好的解决方案将变得有点更精细,而不是使用并ExpectedCondition作为 我们可以使用ExpectedCondition的 如下:

    webdriverwait wait1 = new webdriverwait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();

如果在这种情况下覆盖是永久覆盖,则必须将 实例 为 并执行如下单击操作:

    WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

现在在此特定情况下解决错误 ,我们需要添加 即 ,如下所示:

您需要引起一些 等待 ,以便在HTML DOM中正确显示密码” 字段。您可以考虑为其配置 ExplicitWait 。以下是使用Mozilla Firefox登录Gmail的工作代码

System.setProperty("webdriver.gecko.driver","C:\\Users\\Ruchi\\workspace2\\SeleniumTest\\jar\\geckodriver-v0.17.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
String url = "https://accounts.google.com/signin";
driver.get(url);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
WebElement email_phone = driver.findElement(By.xpath("//input[@id='identifierId']"));
email_phone.sendKeys("error59878@gmail.com");
driver.findElement(By.id("identifierNext")).click();
WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
webdriverwait wait = new webdriverwait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(password));
password.sendKeys("test1");
driver.findElement(By.id("passwordNext")).click();
其他 2022/1/1 18:17:22 有561人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶