Roz*_*een 14 selenium facebook webdriver selenium-webdriver react-native
错误是:
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
Run Code Online (Sandbox Code Playgroud)
代码是:
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();
Run Code Online (Sandbox Code Playgroud)
Deb*_*anB 24
Element is not reachable by keyboard 简单来说意味着使用键盘无法访问该元素,这意味着您甚至无法与其进行物理交互.
错误背后可能有多种原因键盘无法访问元素,可以是以下任一种情况:
hidden属性可以通过以下任一方式实现:
class="ng-hide",style="display: none"等click()或sendKeys()任何<p>或<div>标签,而不是调用click()所需的<input>下列标记为webdriver的官方定位策略.有不同的方法来解决这个问题.
包含临时覆盖使用WebDriverWait与ExpectedConditions连接,以使所需元素可见/可点击,如下所示:
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();
Run Code Online (Sandbox Code Playgroud)来自JavascriptExecutor接口的永久覆盖使用executeScript()方法如下:
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);
Run Code Online (Sandbox Code Playgroud)
您将在使用JS输入文本中找到详细讨论,但如果我在一个文本框中输入文本,则已输入的值将被删除
属性的柜面存在例如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';");
Run Code Online (Sandbox Code Playgroud)
您将在无法填写隐藏文本区域元素中找到详细讨论
如果你看看HTML的Facebook的登录页面,应用程序中包含阵营 本土元素.因此,一个元素一旦与代表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();
Run Code Online (Sandbox Code Playgroud)浏览器客户端
解决错误:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Run Code Online (Sandbox Code Playgroud)
随着Firefox功能的可用性变得更加容易moz:webdriverClick
通过webdriverClick()您可以传递一个布尔值,以指示在执行单击或向元素发送键时要运行哪种交互性检查.对于v58.0之前的Firefoxen,从旧版本的FirefoxDriver导入的一些遗留代码正在使用中.随着Firefox v58的推出,默认情况下会启用WebDriver规范所要求的交互性检查.这意味着geckodriver将另外检查一个元素在点击时是否被另一个元素遮挡,以及一个元素是否可以用于发送键.由于行为的这种变化,我们意识到可能会返回一些额外的错误.在大多数情况下,可能必须更新有问题的测试,以使其符合新的检查.
要临时禁用WebDriver一致性检查false,请将此功能用作值.
注意:此功能仅暂时存在,并且一旦交互性检查已稳定,它将被删除.
| 归档时间: |
|
| 查看次数: |
33301 次 |
| 最近记录: |