Java 如何解决ElementNotInteractiableException:元素在Selenium webdriver中不可见?
这里有我的代码和错误的图像。有人能帮我解决这个问题吗Java 如何解决ElementNotInteractiableException:元素在Selenium webdriver中不可见?,java,selenium,selenium-webdriver,webdriver,webdriverwait,Java,Selenium,Selenium Webdriver,Webdriver,Webdriverwait,这里有我的代码和错误的图像。有人能帮我解决这个问题吗 实际上,异常是元素不可见 最佳实践是在驱动程序实例化下面使用隐式等待,这样它就有足够的时间在整个异常中查找元素 driver.get("http://www.testsite.com"); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 仍然面临问题,因为某些元素需要更多时间。对单个元素使用ExplicitWait,以满足特定条件 在您
实际上,异常是
元素不可见
最佳实践是在驱动程序实例化下面使用隐式等待
,这样它就有足够的时间在整个异常中查找元素
driver.get("http://www.testsite.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
仍然面临问题,因为某些元素需要更多时间。对单个元素使用ExplicitWait
,以满足特定条件
在您的情况下,您将面临元素不可见异常
,然后按以下方式使用等待条件-
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.your_Elemetnt));
实际上,例外情况是
元素不可见
最佳实践是在驱动程序实例化下面使用隐式等待
,这样它就有足够的时间在整个异常中查找元素
driver.get("http://www.testsite.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
仍然面临问题,因为某些元素需要更多时间。对单个元素使用ExplicitWait
,以满足特定条件
在您的情况下,您将面临元素不可见异常
,然后按以下方式使用等待条件-
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.your_Elemetnt));
ElementNotInteractiableException
ElementNotInteractivatableException是W3C异常,抛出该异常是为了指示尽管元素存在于上,但它不处于可与交互的状态
原因和解决办法:
ElementNotInteractiableException发生的原因可能很多
WebElement
临时覆盖在我们感兴趣的WebElement
上:
在这种情况下,直接的解决方案是将
明确地诱导为
与
组合,作为不可见性feelmentlocated
如下:
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();
一个更好的解决方案将是获得更细粒度,而不是使用
作为
我们可以使用
作为可禁用的元素,如下所示:
WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
网站元素
在我们感兴趣的网站元素
上的永久覆盖:
在这种情况下,如果覆盖是永久性的,我们必须将WebDriver
实例转换为JavascriptExecutor
,并执行如下单击操作:
WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
WebElement
临时覆盖在我们感兴趣的WebElement
上:
在这种情况下,直接的解决方案是将
明确地诱导为
与
组合,作为不可见性feelmentlocated
如下:
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();
一个更好的解决方案将是获得更细粒度,而不是使用
作为
我们可以使用
作为可禁用的元素,如下所示:
WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
网站元素
在我们感兴趣的网站元素
上的永久覆盖:
在这种情况下,如果覆盖是永久性的,我们必须将WebDriver
实例转换为JavascriptExecutor
,并执行如下单击操作:
WebDriverWait wait1 = new WebDriverWait(driver, 10);
WebElement element1 = wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element_to_be_clicked")));
element1.click();
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
Javascript的解决方案如下所示。您必须修改时间以满足您的需要
driver.manage().setTimeout({implicit:30000});
希望这对别人有帮助。
参见参考针对Javascript的解决方案如下所示。您必须修改时间以满足您的需要
driver.manage().setTimeout({implicit:30000});
希望这对别人有帮助。
请参阅参考资料我之所以得到这个,是因为我想与之交互的元素被另一个元素覆盖了。在我的情况下,它是一个不透明的覆盖,使一切r/o
当尝试单击另一个元素下的某个元素时,我们通常会得到“…其他元素将收到单击”,但并不总是:。(我之所以这样做,是因为我想与之交互的元素被另一个元素覆盖。在我的情况下,它是一个不透明的覆盖层,使所有内容都是r/o
当尝试单击另一个元素下的某个元素时,我们通常会得到“…其他元素将收到单击”,但并不总是:(当该元素不处于可交互状态时,我们会得到此异常。因此,我们可以使用“等待”,直到找到该元素或使其成为可单击的元素
driver.manage();
WebDriverWait wait=newwebdriverwait(驱动程序,20);
WebElement输入\ u用户名;
input_userName=wait.until(ExpectedConditions.ElementToBickable(按.tagName(“输入”));
输入用户名.sendkeys(“suryap”);
ExpectedCondition.visibilityOfElementLocated()
。
您可以增加时间,例如
WebDriverWait wait=newwebdriverwait(驱动程序,90);
当元素不处于可交互状态时,我们会遇到此异常。因此,我们可以使用“等待”直到元素被定位或可单击
driver.manage(