错误是:
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
代码是:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
在其中一个用例中,我有同样的问题:
在发送键之前使用id标识元素。类似于:
测试之后,我换成了CSS选择器,它解决了这个问题:
因此,我强烈建议使用不同的方法与元素交互,因为其他方法可以节省您解决问题的时间。
您可以尝试以下代码:
试试这个代码,让我知道状态。
ElementNotInteractiveException:键盘无法访问元素
Element is not reachable by keyboard
用简单的词表示,使用键盘无法访问元素,这意味着您甚至不会与元素进行物理交互。原因
键盘无法访问错误元素的背后可能有多种原因,这些原因可能是:
hidden
属性可以通过以下任一方式实现:class="ng-hide"
,style="display: none"
等<p>
或<div>
标记上调用click()
或sendKeys()
,而应在Official locator strategies for the webdriver之后的所需<input>
标记上调用click()
。解决方案
有不同的方法来解决这个问题。
在临时覆盖的情况下,使用WebDriverWait与ExpectedConditions相结合,使所需的元素可见/可单击,如下所示:
对于永久覆盖,使用JavascriptExecutor接口中的^{} 方法,如下所示:
您可以在Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
中找到详细的讨论如果存在属性,例如} 方法编辑并将
class="ng-hide"
,style="display: none"
等,请使用JavascriptExecutor接口中的^{style="display: none"
属性重置为style="display: block"
,如下所示:您可以在Can't fill in the Hidden text area element
中找到详细的讨论参考文献
这个问题
如果查看Facebook登录页面的HTML,应用程序将包含ReactNative元素。因此,在系统中曾经用
id
表示为u0ub的元素,在下次系统上运行时可能不会用与u0ub相同的id
表示。因此,我们必须借助动态定位策略。可以使用以下代码块执行预期步骤:代码块:
浏览器客户端:
更新
解决错误:
随着Firefox功能的可用性,moz:webdriverClick变得更加容易
moz:webdriverClick()
通过
webdriverClick()
可以传递一个布尔值,指示在执行单击或向元素发送键时要运行哪种交互检查。对于Firefoxen在v58.0之前的版本,一些从较旧版本的FirefoxDriver导入的遗留代码正在使用中。使用Firefox v58的可用性,默认情况下,WebDriver specification所需的可交互性检查是启用的。这意味着geckodriver还将检查一个元素在单击时是否被另一个元素遮挡,以及一个元素是否可用于发送键。由于行为上的这种变化,我们知道可能会返回一些额外的错误。在大多数情况下,所讨论的测试可能需要更新,以便与新的检查一致。要临时禁用符合WebDriver的检查,请使用此功能的值。
注意:此功能仅暂时存在,并且一旦稳定了可交互性检查,它将被删除。
相关问题 更多 >
编程相关推荐