Selenium webdriver 由于页面加载时间不同,如何等待找到元素
我正在测试一个电子商务网站,我有一个使用testng框架在selenium中运行的脚本。有时脚本工作正常,有时页面加载速度较慢,并且没有显示找到的元素。我应该如何优化当前代码??任何帮助都可以使用WebDriverWait 它将等待特定条件得到满足。以下代码将等待元素可见:Selenium webdriver 由于页面加载时间不同,如何等待找到元素,selenium-webdriver,xpath,automated-tests,testng,Selenium Webdriver,Xpath,Automated Tests,Testng,我正在测试一个电子商务网站,我有一个使用testng框架在selenium中运行的脚本。有时脚本工作正常,有时页面加载速度较慢,并且没有显示找到的元素。我应该如何优化当前代码??任何帮助都可以使用WebDriverWait 它将等待特定条件得到满足。以下代码将等待元素可见: WebElement element = driver.findElement(By.id("some-valid-element-id")); WebDriverWait wait = new WebDriverWait
WebElement element = driver.findElement(By.id("some-valid-element-id"));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(element));
你可以使用WebDriverWait 它将等待特定条件得到满足。以下代码将等待元素可见:
WebElement element = driver.findElement(By.id("some-valid-element-id"));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(element));
无论您在哪里导航到新网页,都可以使用页面加载超时。 它将等待所有元素加载或等待40秒。所以基本上它会检查两个条件
无论您在哪里导航到新网页,都可以使用页面加载超时。 它将等待所有元素加载或等待40秒。所以基本上它会检查两个条件