【问题标题】:How to overcome the "element not interactable exception"如何克服“元素不可交互异常”
【发布时间】:2020-09-28 07:58:53
【问题描述】:

enter image description here

我尝试过双击方法,Thread.sleep,隐式等待,显式等待(在元素之前和之后),使用 xpath,css 定位器,但我仍然得到 org.openqa.selenium.ElementNotInteractableException: element不可交互异常。 这是最新版本的代码;

//selecting student information tab
driver.findElement(By.cssSelector("div.mat-tab-labels>div:nth-child(2)")).click();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
//enter lastname

// try {
//       new 
WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("ms-text- 
field[placeholder='GENERAL.FIELD.LAST_NAME']"))).click();
//  driver.findElement(By.cssSelector("ms-text- 
field[placeholder='GENERAL.FIELD.LAST_NAME']")).sendKeys("Abuzer");
// } catch (Exception e){}

 WebElement lname = driver.findElement(By.xpath("//ms-text-field[@formcontrolname='lastName']"));
 lname.click();
 driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
 lname.sendKeys("John");`

我还分享了对我不起作用的评论部分。

【问题讨论】:

  • 您是否检查过iframe 的存在?在您使用“Xpath”的最后一次测试中,如果您针对 input 元素而不是 ms-text-field 会发生什么?类似:WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath("//ms-text-field[@formcontrolname='lastName']/input"))).click();
  • 成功了!感谢您的帮助。我想我同时使用 css 选择器和 xpath 定位器把它搞砸了。我只是将 xpath 用于 click() 和 sendkeys() 方法。
  • 不错,玩的不错。我已将我的评论添加为可能面临相同问题的用户的答案。

标签: java selenium xpath css-selectors


【解决方案1】:

你检查过 iframe 的存在吗?

在您使用“Xpath”的最后一次测试中,如果您以输入元素而不是 ms-text-field 为目标会发生什么?类似的东西:

WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath("//ms-text-field[@formcontrolname='lastName']/input"))).click();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-22
    • 2020-12-08
    • 2020-11-14
    • 2020-02-11
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    相关资源
    最近更新 更多