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
118 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
• 57,940 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 Jan 13 in Selenium by Karan
• 16,050 points
2,607 views
+1 vote
1 answer
0 votes
2 answers
0 votes
2 answers

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
3,525 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,533 views
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,890 points
2,595 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,862 views
+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27 in Selenium by Sirajul
• 57,940 points
363 views
+2 votes
1 answer