How to use selenium getpagesource for work?
Q&A for work Connect and share knowledge within a single location that is structured and easy to search. Learn more Selenium: getPageSource() returns previous pages’ source Ask Question Asked4 years, 6 months ago Active2 years, 4 months ago Viewed28k times 6
How to get the previous page in selenium?
Learn more Selenium: getPageSource() returns previous pages’ source Ask Question Asked4 years, 6 months ago Active2 years, 4 months ago Viewed28k times 6 I’m logging into the page using this function:
How to use Webdriver in Java selenium?
Here, driver is your WebDriver object from which you call getPageSource () ( javadoc) method which returns a String object containing the source code of the loaded website. Now on that returned String object, you are calling contains () method which checks whether the String includes (or contains) the text you passed in the argument.
Which is the method of WebDriver getpagesource ( )?
Here driver is an object ob WebDriver class . getPageSource () is method of WebDriver class. So driver.getPageSource () returns source code of the page which stored as string. contains is method of a String class to check if a string contains in another string.
How to perform assertion on text in selenium 2?
In RC and IDE we have option to validate or verify any text on the page by using methods like or in IDE we normally select the text and by right-clicking we normally add assert or verify method for specific text. But Selenium 2 (WebDriver) doesn’t have any direct method to find the text and also doesn’t have any assertion associated with it.
How to check if selenium login is successful?
The login is successful and now i’d like to verify this by checking for certain elements on the landing page as follows: public static void testLogin(WebDriver driver) { String pageSource = driver.getPageSource(); //Assert.assertTrue(“Login was not successful!”, pageSource.contains(“Welcome to the page!”));
How to check source code in Java selenium?
So driver.getPageSource () returns source code of the page which stored as string. contains is method of a String class to check if a string contains in another string. So, driver.getPageSource ().contains (“Text to find”); will return True if ‘Text to find’ is found in page source code else False.