How to Find Web element by Id and class

While I’m at it, in your other question about how many “pages”, since you know Selenium, and you notice all the Pages have a class containing “dx-page” and tabindex = 0 and role = “button”, so how about see if the below works.

List<WebElement> pages = driver.findElements('//div[contains(@class, "dx-page") and @tabindex="0" and @role="button"]');
int pageCount = pages.size();
println("We found ${pageCount} pages")

for (int cnt = 0; cnt < pageCount; cnt++) {

1 Like

List pages = driver.findElements(’//div[contains(@class, “dx-page”) and @tabindex=“0” and @role=“button”]’);
int pageCount = pages.size();
println(“We found ${pageCount} pages”)

for (int cnt = 0; cnt < pageCount; cnt++) {


this might work but I have Two divs that that contain The same elements
let me explain more Braccj
we have div with many sub divs that has ID: BrachTypes_tab and another with ID: CustomerTypes_Tab

each has “dx-page” inside them and i only want to access the one of ID: BrachTypes_tab

and when i use your code or another FindElemet fucntion it only finds/access the first one which is the CustomeTypes_Tab

Yup, and remember how we were able to start at a “parent” element and move down to a “child”, like we did in the above quote. So we do something similar, like maybe:

List<WebElement> pages = driver.findElements('id("BranchTypes_Tab")//div[contains(@class, "dx-page") and @tabindex="0" and @role="button"]');

If this doesn’t work, then try to use another id or reference that makes the pathway unique. (You may even have to insert other “between” tags–other “child” elements in between our starting element and the element we want–so the pathway is unique.)

Now the format I use works for id. If you start at another reference that does not have an id, then change the start to:

List<WebElement> pages = driver.findElements('//div[@class="dx-widget dx-visibility-change-handler"]//div[contains(@class, "dx-page") and @tabindex="0" and @role="button"]');
1 Like

Hi Team,

Please assist, am trying to find the following element but without success

I am using the following xpath : //*[@name=“ddlelementCashFunder_hidden”]/li[contains(text(),‘Absa’)]

I notice there are several references of hidden for the attributes of this select tag. This is not the element you want or maybe this element is not available for selection at this time.

Also, your xpath would not be correct for the select tag. You would just use:
(there’s that hidden again)

and then you would use one of the below:
WebUI.selectOptionByValue(findTestObject('our object'), '12')
WebUI.selectOptionByLabel(findTestObject('our object'), 'Absa')

@grylion54, thanks i got it right by rewriting the whole xpath: and the below is the one working

//ul[@id=‘ddlelementCashFunder_options’]/li[contains(text(), ‘Absa’)]