How can I automate Menu links of a website and validate page titles? Please help.

0 votes
How can I automate Menu links of a website and validate page titles? Please help.
Aug 20, 2019 in Selenium by Khushi
40 views

1 answer to this question.

0 votes

You could probably try following these steps where first you would collect all the links of the webpage and validate them:

1) Navigate to the interested webpage.

2) Create a list of type WebElement to store all the Link elements in to it.

3) Collect all the links from the webpage. All the links are associated with the Tag ‘a‘.

4) Now iterate through every link and print the Link Text on the console screen.

package practiceTestCases;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FindAllLinks {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://edureka.com/");
java.util.List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println(links.size());
for (int i = 1; i<=links.size(); i=i+1)
{
System.out.println(links.get(i).getText());
}
}
}

The same way you can easily be able to find any type of WebElements on a WebPage:

Find total number of Menus on a Webpage :

java.util.List;WebElement&gt; dropdown = driver.findElements(By.tagName("select"));  
System.out.println(dropdown.size());

Hope this helps!

answered Nov 29, 2019 by Sirajul
• 44,350 points

Related Questions In Selenium

+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered 6 days ago in Selenium by Karan
• 7,520 points
238 views
+1 vote
1 answer
0 votes
2 answers
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
1,472 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,850 points
1,454 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,850 points
1,217 views
0 votes
1 answer

How to write a feature file in Cucumber?

A Feature File is an entry point to the Cucumber tests. ...READ MORE

answered Nov 27, 2019 in Selenium by Sirajul
• 44,350 points
36 views
0 votes
1 answer

What is Behavior Driven Development (BDD) and what are its features?

Behavior-driven development (BDD) is an Agile software development methodology within which an application is ...READ MORE

answered Nov 27, 2019 in Selenium by Sirajul
• 44,350 points
50 views