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
3,126 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
• 59,230 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, 2020 in Selenium by Karan
• 19,610 points
7,806 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,500 points
12,619 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 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,910 points
6,629 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 3, 2020 in Selenium by Sri
• 3,190 points
7,519 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, 2020 in Selenium by Sirajul
• 59,230 points
1,790 views
+2 votes
1 answer

What is asynchronous script? Why selenium use setScriptTimeout() command and how it help us?

Asynchronous scripts are used for rendering the ...READ MORE

answered Feb 3, 2020 in Selenium by Sirajul
• 59,230 points
2,222 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP