- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
错误是:
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();
最佳答案
ElementNotInteractableException:无法通过键盘访问元素Element is not reachable by keyboard
简而言之,这意味着无法使用键盘访问该元素,这意味着您甚至无法与它进行物理交互。
原因
键盘无法访问错误元素背后可能有多种原因,这可能是以下任一原因:
hidden
属性可以通过以下任一方式实现:class="ng-hide"
, style="display: none"
等 click()
或 sendKeys()
在任何 <p>
或 <div>
标记,而是调用 click()
在所需的 <input>
标签在 Official locator strategies for the webdriver 之后. import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.nsg-button"))).click();
executeScript()
方法来自 JavascriptExecutor界面如下:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);
class="ng-hide"
, style="display: none"
等使用 executeScript()
方法来自 JavascriptExecutor界面编辑和重置 style="display: none"
归因于 style="display: block"
如下:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");
id
表示如
u_0_b 在您的系统中可能不是由相同的
id
表示的如
u_0_b 下次在你的系统上运行。因此,我们必须借助动态定位器策略。您可以使用以下代码块来执行您的预期步骤:
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).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.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
webdriverClick()
您可以传递一个 bool 值来指示在执行单击或向元素发送键时要运行的交互性检查类型。对于
之前的 Firefoxen v58.0 从旧版本
FirefoxDriver 导入的一些遗留代码正在使用中。随着
的可用性火狐 v58
WebDriver specification 要求的交互性检查默认情况下启用。这意味着 geckodriver 将额外检查一个元素在单击时是否被另一个元素遮挡,以及一个元素是否可聚焦以发送键。由于这种行为变化,我们知道可能会返回一些额外的错误。在大多数情况下,有问题的测试可能需要更新,以符合新的检查。
false
作为此功能的值(value)。
关于facebook - org.openqa.selenium.ElementNotInteractableException : Element is not reachable by keyboard: while sending text to FirstName field in Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49864965/
我有两个单独收集的同一组学生的姓名列表。有许多打印错误,我一直在使用模糊匹配来链接这两个列表。我 99+% 有 agrep和类似的,但我坚持以下基本问题:我如何匹配(例如)名字“Adrian Bruc
我有一个名字列表,我需要将这些名字从“名字姓氏”转换为“姓氏,名字”。 Barack Obama Donald J. Trump J. Edgar Hoover Beyonce Knowles-Car
我有一栏写满了名字: “姓氏,名字” 我想要另一列,该姓名列表写为: “名字 姓氏” 那么,如何将字符串从“lastName,firstName”切换为“firstName LastName”? 最佳
我正在尝试将包含某人姓名的字符串转换为“Last, First”到“First Last”。 这就是我现在的做法: name = name.Trim name = name.Substring(nam
我想将其更改为名字和姓氏的首字母。 谢谢! 最佳答案 NSString* nameStr = @"Firstname Lastname"; NSArray* firstLastStrings = [n
如何在 Postgres 中将表列数据从“LastName, FirstName”转换为“FirstName LastName”。 因此,如果表列包含“Ona, Lisa”,我希望它返回“Lisa O
我有 python pandas 数据框,由用于执行 python 脚本的 power bi 数据源转换支持提供,其中一列由 lastname, firstname 组成,我需要它由 名字姓氏。 我尝
我有 python pandas 数据框,由用于执行 python 脚本的 power bi 数据源转换支持提供,其中一列由 lastname, firstname 组成,我需要它由 名字姓氏。 我尝
我正在处理我的作业,我几乎完成了代码。我只是需要有关独特设计的帮助。 我有 3 个带有一些文本的按钮。对于全屏,文本是 "HelloWorld"、"LastFirst",但是当在移动设备上看到相同的网
我正在开发一个网页,该网页将在我的数据库中显示用户的信息。首先,我编写了一些代码来从数据库中获取名字并对其进行回显。我最初测试的用户的每个字段(用户名、名字、姓氏、密码)都填写为 "1" .为了进一步
我有一段代码,根据您使用的内部函数返回名字和姓氏或名字和中间名。但是,当使用 this 关键字时,当我访问姓氏或中间名内部函数时,名字返回未定义。如果我不使用“this”,那么名字就可以正常返回。我不
我知道我为什么会收到错误,但我不知道代码是什么 我得到的错误是 must declare the scalar variable "@OTitle@FirstName" 我的方法看起来像这样.. cm
想知道在允许通过非唯一自然名称提及其他用户的数据库 (sql) 中存储评论的最佳方式是什么? 例如This is a comment for @John. 如果点击他/她的名字,客户端应用程序还需要检
该问题已在其他地方问过,但没有回答。 谷歌浏览器认为我的输入 是一张信用卡,如自动完成字段检查器(实验标志 thingy)和提供已保存信用卡的自动完成所示。 它也在 lastName 字段和另一个数
@{DisplayName=Firstname Lastname} 需要只是 'Firstname Lastname' 因为 get-mailbox -identity '@{DisplayName=
将字符串“Parisi, Kenneth”分成“Kenneth”和“Parisi”的最佳方法是什么? 我仍在学习如何使用这些正则表达式解析字符串,但不太熟悉如何将 vars 设置为等于匹配的字符串和匹
我四处搜寻,但找不到任何帮助。 我正在尝试创建一个用户,但有 2 个字段始终为空(名字和部门)。 GUI (html): Firstname:
在我正在使用的表格中,full_name 列的格式为“Firstname Lastname” 例如。 “约翰·韦斯特” 我正在使用这个: $q="John"; $sql = "SELECT full_
我遍历一长串名字,我将每个名字分配给一个“人”对象。 Person 对象有一个 firstName 和一个 lastName。我正在寻找一种有效的方法来对从字母 A 到 Z 开头的所有 firstNa
我不想太严格,因为一个可能的名字中可能有数千个可能的字符 普通英文字母、重音字母、非英文字母、数字(??)、常用标点符号 例如 D'souza D'Anza M.D. Shah (dots and s
我是一名优秀的程序员,十分优秀!