栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

ElementNotInteractableException

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

原因与解决方案:

ElementNotInteractableException 发生的原因可能很多。

  1. 将其他 WebElement 临时覆盖在我们感兴趣的 WebElement 上:

在这种情况下,直接的解决方案将是,以诱导 ExplicitWaitWebDriverWait 结合

ExpectedCondition

invisibilityOfElementLocated
如下:

    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
作为
invisibilityOfElementLocated
我们可以使用
ExpectedCondition

elementToBeClickable
如下:

    WebDriverWait wait1 = new WebDriverWait(driver, 10);WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));element1.click();
  1. 将其他 WebElement 永久覆盖在我们感兴趣的 WebElement 上:

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

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

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

您需要引起一些 等待 ,以便在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();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/415556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号