0

I am stuck in a problem and searched a couple of days. I am testing a website using selenium in python, I want to check the working of "About Us" button. In that website, clicking "About US" will scroll the page smoothly and take you to that "About US" section. Now I want to confirm with code, that did that clicking took me to the write section or not?

The first logic came in my mind was to check that either the main division of "About US" section is in viewport after clicking the button? But I don't know how to check it. I have gone through the documentation and found is_displayed() method but that is used to see is the item is visible or not (like its opacity etc) Kindly help me. Regards

  • try the `driver.current_url` and check if the term `about` in url – Mouad Slimane Sep 30 '22 at 10:55
  • Once 'About Us' page is loaded, check the page title (or) check for a unique page header and ensure that the page header is displayed through code (or) check for any unique element and ensure that the element is displayed. – AbiSaran Sep 30 '22 at 11:25
  • 2
    Please provide enough code so others can better understand or reproduce the problem. – Community Sep 30 '22 at 15:04

1 Answers1

0

There are many ways to assert for correct page loaded, most used are the assert for correct url loaded and page title.

Assert for Correct URL Loaded:

    String expectedUrl = "https://www.google.com";
    WebDriver driver = new FirefoxDriver();
    driver.get(expectedUrl);
    try{
      Assert.assertEquals(expectedUrl, driver.getCurrentUrl());
      System.out.println("Navigated to correct webpage");
    }
    catch(Throwable pageNavigationError){
      System.out.println("Didn't navigate to correct webpage");
    }

Assert for page title:

String expectedTitle = "Google";
String expectedUrl = "https://www.google.com";
WebDriver driver = new FirefoxDriver();
driver.get(expectedUrl);
try{
  Assert.assertEquals(expectedTitle, driver.getTitle());
  System.out.println("Navigated to correct webpage");
}
catch(Throwable pageNavigationError){
  System.out.println("Didn't navigate to correct webpage");
}
Akzy
  • 1,817
  • 1
  • 7
  • 19
  • Thanks dear, but as I mentioned when we click that button, the page scrolls down to the respective section of the site, neither the url of the page changes nor the title of the page changes. This is because I am stuck that what I should do now... I am sending the link to the site, if you can check it and suggest me what to do. https://www.urraan.pk/ Click on any nav bar button and tell me how can I code to tell the compiler that Yes! you moved to About Us section – anwaar ahmad Sep 30 '22 at 14:06