我的Java中的Selenium存在以下问题。它会生成错误,该元素不再附加到DOM(org.openqa.selenium.StaleElementReferenceException
)。我找到了一些等待的解决方案,但它们不起作用(wait.driver,Thread.sleep)。
我已尝试过以下代码,但它无效:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath1)));
driver.findElement(By.xpath(xpath1)).clear();
driver.findElement(By.xpath(xpath1)).sendKeys("A");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath2)));
driver.findElement(By.xpath(xpath2)).clear();
driver.findElement(By.xpath(xpath2)).sendKeys("B");
如何使用Java在Selenium WebDriver中解决此问题?将不胜感激任何帮助。
答案 0 :(得分:-1)
我设法解决了,但这不是太漂亮的解决方案:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath1)));
driver.findElement(By.xpath(xpath1)).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(xpath1)).sendKeys("A");
Thread.sleep(1000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath2)));
driver.findElement(By.xpath(xpath2)).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(xpath2)).sendKeys("B");
我认为Page很慢,可能是数据库的操作很慢或与此类似。