- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用此功能登录页面:
public static void login() {
driver.get(url);
driver.findElement(By.name("username")).clear();
driver.findElement(By.name("username")).sendKeys("username- login");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.name("submit")).click();
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
登录成功,现在我想通过检查登录页面上的某些元素来验证这一点,如下所示:
public static void testLogin(WebDriver driver) {
String pageSource = driver.getPageSource();
//Assert.assertTrue("Login was not successful!", pageSource.contains("Welcome to the page!"));
System.out.println(pageSource);
一切正常,除了当我在控制台上显示源代码时,它是登录页面的源代码(以前的 url),因此 Assert 返回 false。
谁能指出我正确的方向?
最佳答案
您可以等待一段时间,直到新页面打开:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[contains(.,'Welcome to the page!')]")));
这应该允许您等到新页面中包含文本值 'Welcome to the page!'
的元素出现在 DOM
或者您可以等到页面标题更改:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.titleContains("New page title"));
关于java - Selenium:getPageSource() 返回前一页的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41743457/
我正在尝试验证一些文本,例如在 Python、Webdriver 中使用 driver.getPageSource 的网页上的“test001”。我收到错误对象没有属性“getPageSource”:
我需要程序中给出的url的来源。但是程序只返回一些 json 数据而不是整个页面源。有什么问题?? public class selenium { public static void main(St
我正在使用此功能登录页面: public static void login() { driver.get(url); driver.findElement(By.name("userna
我正在尝试编写一段代码,用户在其中输入Python,然后按回车键,这个应用程序“Python教程教程点”位于第四页。我的逻辑是:使用 getPageSource 找到该项目并继续单击“下一步”按钮。然
我正在使用 WebDriver 和 java 来获取页面源。使用 FirefoxDriver 我试图验证页面源上的一些文本,但是当我使用 driver.getPageSource 时,它会将一些符
下面这段代码的完整含义是什么?我的意思是,哪个对象实现哪个类并使用哪个方法? driver.getPageSource().contains("Text to find"); 最佳答案 让我们一个接一
我正在尝试使用 selenium 获取页面源 String ps = driver.getPageSource(); 但是页面源里面的链接是相对的,比如 因此我无法使用此源代码,因为图像/css 未
我正在尝试使用 selenium 将指定 URL 中的源代码捕获到 HTML 文件中,但我不知道为什么,我没有获得我们从浏览器中看到的确切源代码。 下面是我在 HTML 文件中捕获源代码的 java
我是 Selenium 的新手,想知道是否有人可以指出正确的方向。 我正在尝试获取页面的页面源,但我注意到 IE 驱动程序返回了一些东西不同于 FirefoxDriver。 此外,InternetEx
在使用 selenium 时,刚才我在解析 selenium getPageSource() 方法的输出时遇到错误。firefox页面源实际的meta标签= 使用带有 selenium = 的
当我尝试显示页面的源代码时, res.json 返回空白。 Selenium 日志显示已检索到源代码。知道如何正确接收更新的页面源吗? 如果我使用其他函数(例如获取当前网址),它会返回相同的结果。 代
我正在抓取一些网页,我注意到 rvest(read_html,然后 html_text)提供的结果与 RSelenium(getPageSource())提供的结果不同。 更具体地说,当涉及下拉菜单时
如何使用 Selenium WebDriver 和 Java 查看“title”和“meta”标签之间的页面源代码? 最佳答案 加载页面后,您可以尝试 driver.getPageSource()。
如何使用带有 Java 的 Selenium WebDriver 查看“title”和“meta”标签之间的页面源代码? 最佳答案 您可以在加载页面后尝试 driver.getPageSource()
我是一名优秀的程序员,十分优秀!