XPath for the elements with no ID or Name in Selenium Webdriver

0 votes

I tried to automate the code which with no IDs on many elements, and a lot of elements with the same class names. Need some help in the following questions

<div id="author-taxonomies" class="menu-opened menu-hover-opened-inactive" onmouseover="styleMenuElement(this)" onmouseout="styleMenuElement(this)" onclick="toggleSFGroup(this)">Author</div>
<div id="author-taxonomies-div" class="opened">
    <div id="top-level-menu" class="opened">
        <div id="top-level-menu-item-1" class="as-master">
            <div class="filter-label"> Name</div>
        </div>
        <div id="top-level-menu-item-1" class="as-slave"
            style="top: 525px; left: 34px; z-index: 100; display: none;"> </div>
        <div id="top-level-menu-item-2" class="as-master">
            <div class="filter-label">Title</div>
        </div>
        <div id="top-level-menu-item-2" class="as-slave">
            <div id="top-level-menu-item-2" class="as-slave-title as-slave-title-subgroup"
               >Title</div>
            <div id="top-level-menu-item-2" class="as-slave-body"> </div>
            <div class="as-slave-buffer"> </div>
        </div>
        <div id="top-level-menu-item-3" class="as-master">
            <div class="filter-label">Location</div>
        </div>
        <div id="top-level-menu-item-3" class="as-slave"> </div>
    </div>
</div>

Problem is how to refer specific labels for this menu and the properties with xPath expressions? For example, if I want to:

  1. verify the "Location" label is there
  2. check if "Title" with class "as-slave" is not visible at the moment
Apr 17, 2018 in Selenium by king_kenny
• 3,710 points
7,382 views

1 answer to this question.

0 votes

Use like this or similar to this:

  • //div[@id="top-level-menu-item-3"]/div[@class="filter-label"]
  • //div[@id="top-level-menu1"]  for selenium RC

answered Apr 17, 2018 by Meci Matt
• 9,460 points

Related Questions In Selenium

0 votes
2 answers

what is the need of xpath when you have attributes like id ,class,name in selenium?

some of the controls not have id ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
1,800 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,923 views
0 votes
1 answer

Searching for the element with &nbsp; symbol in selenium

Use Below: //div[@class='Tips' and text()='\u00a0'] READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,360 points
9,333 views
0 votes
1 answer

Between By.XPath and By.ID, which is the better for locating elements?

Technically speaking, By.ID() is the faster technique ...READ MORE

answered May 30, 2018 in Selenium by sniffy_god
• 780 points
12,639 views
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
13,687 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
9,149 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
7,229 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,880 views
0 votes
2 answers

Check that the element is clickable or not in Selenium WebDriver

Hi , you want to know only is ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
34,206 views
0 votes
1 answer

Which is preferred more in Selenium Absolute or Relative XPath

Absolute XPath is the direct way to ...READ MORE

answered Apr 20, 2018 in Selenium by Meci Matt
• 9,460 points
4,468 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