通过Selenium的显式等待
单击下面的站点文本中的链接“单击以加载通过Ajax获取数据!”将出现,我正在尝试使用显式等待将其打印出来。它没有打印文本通过Selenium的显式等待,selenium,selenium-webdriver,webdriverwait,Selenium,Selenium Webdriver,Webdriverwait,单击下面的站点文本中的链接“单击以加载通过Ajax获取数据!”将出现,我正在尝试使用显式等待将其打印出来。它没有打印文本 import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.ope
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Explicitwait {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Aditya\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.itgeared.com/demo/1506-ajax-loading.html");
System.out.println(driver.findElement(By.xpath("//*[@id='results']")).isDisplayed());//false
driver.findElement(By.xpath("//*[@id='content']/a[2]")).click();
System.out.println("click on the link");
WebDriverWait d = new WebDriverWait(driver, 10);
d.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='results']")));
System.out.println(driver.findElement(By.xpath("//*[@id='results']")).isDisplayed());//true
System.out.println(driver.findElement(By.xpath("//*[@id='results']")).getText());
}
}
要获取文本,请使用
元素定位的可见性
而不是元素定位的显示
:
WebDriverWait d = new WebDriverWait(WebDriverRunner.getWebDriver(), 10);
d.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='results']")));
要获取文本,请使用
元素定位的可见性
而不是元素定位的显示
:
WebDriverWait d = new WebDriverWait(WebDriverRunner.getWebDriver(), 10);
d.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='results']")));
您是否收到任何错误或文本未打印?早期文本未打印…在将其从状态更改为可见性后,它工作且正在打印您是否收到任何错误或文本未打印?早期文本未打印…在将其从状态更改为可见性后,它工作且正在打印获取打印任务任务…从工作状态更改为可见性任务…从工作状态更改为可见性任务