尝试使用Selenium打印段落时获取空白字符串
打开网站我正在切换框架并单击下面显示的第一个图像。在下一页上,我想在标题 Selenium 3.0培训下打印任何一段。但是我在控制台上得到了空的响应。请帮忙。
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\nehra\\newSeleniumWorkspace\\tryypanda\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.globalsqa.com/demo-site/frames-and-windows/#iFrame");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
WebElement iframe1=driver.findElement(By.xpath("//*[@id=\"post-2632\"]/div[2]/div/div/div[3]/p/iframe"));
driver.switchTo().frame(iframe1);
driver.findElement(By.xpath("//*[@id=\"portfolio_items\"]/div[1]/a/div/div/div[1]/img")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame("globalSqa");
String getparatext=driver.findElement(By.xpath("//*[@id=\"wrapper\"]/div/div[2]/div/div/div/p[1]/span")).getText();
System.out.println(getparatext);
}
`
After opening Website I'm switching frames and click on the first image shown below. On the next page, I want to print any one paragraph under the title Selenium 3.0 Training. But I'm getting an empty response in the console. Please help.
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Users\\nehra\\newSeleniumWorkspace\\tryypanda\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.globalsqa.com/demo-site/frames-and-windows/#iFrame");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
WebElement iframe1=driver.findElement(By.xpath("//*[@id=\"post-2632\"]/div[2]/div/div/div[3]/p/iframe"));
driver.switchTo().frame(iframe1);
driver.findElement(By.xpath("//*[@id=\"portfolio_items\"]/div[1]/a/div/div/div[1]/img")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame("globalSqa");
String getparatext=driver.findElement(By.xpath("//*[@id=\"wrapper\"]/div/div[2]/div/div/div/p[1]/span")).getText();
System.out.println(getparatext);
}
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题:只有在屏幕滚动之后才能看到文字。因此,在切换帧后添加鼠标滚动事件对我有帮助。
Issue: text was getting visible only after the screen was scrolled. So, adding a mouse scroll event after switching frames helped me.