Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - Find a child element under a DIV

Can someone help me with the below HTML:

<div id="ext-156" class="menuBar">
  <a id="ext-234" href="javascript:void(0);" class="active">
    <i id="ext-365" class="menuItem"></i>
  </a>
</div> 

I am looking for the element with class "menuItem" and only from inside the div with class "menuBar" in Selenium.

like image 284
bpk Avatar asked May 19 '15 15:05

bpk


1 Answers

Well, depending on what language you're using, the method call will be different, but the selector should be the same across language bindings:

css:

"div.menuBar .menuItem"

xpath:

"//div[@class='menuBar']//*[@class='menuItem']"

In java, the call would look like this:

driver.find(By.cssSelector("div.menuBar .menuItem"));
like image 194
aholt Avatar answered Sep 23 '22 01:09

aholt