0

I am new to Selenium 2.0 and WebDriver and any help and suggestions on how I can resolve my issue are welcome.

The html code that I am looking at is:

<html>
<head>
<body class="index">
    <div class="container">
    <div class="masthead">
    <div class="status-bar">
    <div class="app-vpn-selector-container">
    <div id="page_tabs" class="tabs">
    <div class="tab-group monitoring">
    <div class="tab-group-name"> Monitoring </div>
    <div class="tab active"> Status </div>
    <div class="tab"> Events </div>
    <div class="tab"> Reports </div>
    <div class="tab"> Statistics </div>
    </div>
    <div class="tab-group configuration">
    </div>
    <div id="page_content" class="tab_content">
    </div>
 </body>
</html>

The task I have is to store all the names of the tabs: Status, Events, Reports, Statistics and assert that the values exist.

List<WebElement> allTabs = webdriver1.findElements(By.xpath("//div[@id='page_tabs']/div/div"));

will get me to the element but I cannot read the attribute values. Could someone let me know how to resolve it. I have spent a lot of time reading information online, but could not find a solution. Thanks in advance

0

2 Answers 2

1

findElements returns a List. It would give you all the second level divs based on your xpath. What you need to do once you get the list is to iterate through the elements and call the getText method and verify the text u get..something to the effect

 List<WebElement> lstElements = driver.findElementsByXPath("//div[@id='page_tabs']/div/div");

   for (WebElement e : lstElements){
        //Verify e.getText() matches the expected value
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Hey if you are facing issue in reading the Text (Names of Tabs)...then getText() is the method you are looking for...

String K= Driver.findElements(By.xpath("Main tab Exp")).FindElement(By.xpath("Tab Exp")).getText();

I hope this solves the issue. All the best :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.