<tfoot id='Xk7xj'></tfoot>

<legend id='Xk7xj'><style id='Xk7xj'><dir id='Xk7xj'><q id='Xk7xj'></q></dir></style></legend>

        <small id='Xk7xj'></small><noframes id='Xk7xj'>

      1. <i id='Xk7xj'><tr id='Xk7xj'><dt id='Xk7xj'><q id='Xk7xj'><span id='Xk7xj'><b id='Xk7xj'><form id='Xk7xj'><ins id='Xk7xj'></ins><ul id='Xk7xj'></ul><sub id='Xk7xj'></sub></form><legend id='Xk7xj'></legend><bdo id='Xk7xj'><pre id='Xk7xj'><center id='Xk7xj'></center></pre></bdo></b><th id='Xk7xj'></th></span></q></dt></tr></i><div id='Xk7xj'><tfoot id='Xk7xj'></tfoot><dl id='Xk7xj'><fieldset id='Xk7xj'></fieldset></dl></div>
        • <bdo id='Xk7xj'></bdo><ul id='Xk7xj'></ul>
      2. Selenium WebDriver 在线程“main"中抛出异常.org.openqa.selenium.E

        时间:2023-07-13
        • <bdo id='c8Nni'></bdo><ul id='c8Nni'></ul>
          <i id='c8Nni'><tr id='c8Nni'><dt id='c8Nni'><q id='c8Nni'><span id='c8Nni'><b id='c8Nni'><form id='c8Nni'><ins id='c8Nni'></ins><ul id='c8Nni'></ul><sub id='c8Nni'></sub></form><legend id='c8Nni'></legend><bdo id='c8Nni'><pre id='c8Nni'><center id='c8Nni'></center></pre></bdo></b><th id='c8Nni'></th></span></q></dt></tr></i><div id='c8Nni'><tfoot id='c8Nni'></tfoot><dl id='c8Nni'><fieldset id='c8Nni'></fieldset></dl></div>
          <legend id='c8Nni'><style id='c8Nni'><dir id='c8Nni'><q id='c8Nni'></q></dir></style></legend>

            <small id='c8Nni'></small><noframes id='c8Nni'>

                  <tbody id='c8Nni'></tbody>
                  <tfoot id='c8Nni'></tfoot>
                  本文介绍了Selenium WebDriver 在线程“main"中抛出异常.org.openqa.selenium.ElementNotInteractableException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  测试场景:尝试捕获并测试 Gmail 登录.

                  Test Scenario: Trying to capture and test Gmail Login.

                  当前输出: Mozilla 实例打开.输入了用户名,但是WebDriver 代码未输入密码.

                  Current Output: Mozilla instance opens up. Username is entered but the Password is not being entered by the WebDriver code.

                  System.setProperty("webdriver.gecko.driver", "C:\Users\Ruchi\workspace2\SeleniumTest\jar\geckodriver-v0.17.0-win64\geckodriver.exe");
                  FirefoxDriver  varDriver=new FirefoxDriver();
                  
                  varDriver.get("http://gmail.com");  
                  WebElement webElem=  varDriver.findElement(By.id("identifierId"));
                  webElem.sendKeys("error59878@gmail.com");
                  WebElement nextButton=varDriver.findElement(By.id("identifierNext"));
                  nextButton.click();
                  
                  varDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                  
                  WebElement wePass=varDriver.findElement(By.cssSelector(".rFrNMe.P7gl3b.sdJrJc.Tyc9J"));
                  
                  wePass.sendKeys("test1");
                  

                  推荐答案

                  ElementNotInteractableException

                  根据文档,ElementNotInteractableException 是 W3C 异常,它被抛出以表明尽管元素存在于 DOM Tree,不是可以交互的状态.

                  ElementNotInteractableException

                  As per the documentation, ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the DOM Tree, it is not in a state that can be interacted with.

                  ElementNotInteractableException 发生的原因有很多.

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

                  在这种情况下,直接的解决方案是诱导 ExplicitWaitWebDriverWait 结合 ExpectedCondition 作为 invisibilityOfElementLocated如下:

                  In this case, the direct solution would have been to induce ExplicitWait i.e. WebDriverWait in combination with ExpectedCondition as invisibilityOfElementLocated as follows:

                  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 我们可以使用 ExpectedConditionelementToBeClickable 如下:

                  A better solution will be to get a bit more granular and instead of using ExpectedCondition as invisibilityOfElementLocated we can use ExpectedCondition as elementToBeClickable as follows:

                  WebDriverWait wait1 = new WebDriverWait(driver, 10);
                  WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
                  element1.click();
                  

                • 将其他 WebElement 永久覆盖在我们感兴趣的 WebElement 之上:

                • Permanent Overlay of other WebElement over the WebElement of our interest :

                  如果在这种情况下叠加层是永久的,我们必须将 WebDriver 实例转换为 JavascriptExecutor 并执行如下点击操作:

                  If the overlay is a permanent one in this case we have to cast the WebDriver instance as JavascriptExecutor and perform the click operation as follows:

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

                • <小时>

                  现在解决此特定上下文中的错误 ElementNotInteractableException,我们需要添加 ExplicitWaitWebDriverWait,如下所示:


                  Now addressing the error ElementNotInteractableException in this particular context we need to add ExplicitWait i.e. WebDriverWait as follows :

                  您需要诱导一点 wait 以使 Password 字段在 HTML DOM 中正确呈现.你可以考虑为它配置一个ExplicitWait.以下是使用 Mozilla Firefox 登录 Gmail 的工作代码:

                  You need to induce a bit of wait for the Password field to be properly rendered in the HTML DOM. You can consider configuring an ExplicitWait for it. Here is the working code to login into Gmail using Mozilla Firefox:

                  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();
                  

                  这篇关于Selenium WebDriver 在线程“main"中抛出异常.org.openqa.selenium.ElementNotInteractableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:等待 Selenium 中的页面加载 下一篇:Selenium WebDriver 如何解决陈旧元素引用异常?

                  相关文章

                  <tfoot id='L8L73'></tfoot>

                  • <bdo id='L8L73'></bdo><ul id='L8L73'></ul>
                • <legend id='L8L73'><style id='L8L73'><dir id='L8L73'><q id='L8L73'></q></dir></style></legend>

                  1. <i id='L8L73'><tr id='L8L73'><dt id='L8L73'><q id='L8L73'><span id='L8L73'><b id='L8L73'><form id='L8L73'><ins id='L8L73'></ins><ul id='L8L73'></ul><sub id='L8L73'></sub></form><legend id='L8L73'></legend><bdo id='L8L73'><pre id='L8L73'><center id='L8L73'></center></pre></bdo></b><th id='L8L73'></th></span></q></dt></tr></i><div id='L8L73'><tfoot id='L8L73'></tfoot><dl id='L8L73'><fieldset id='L8L73'></fieldset></dl></div>

                      <small id='L8L73'></small><noframes id='L8L73'>