kamal kumar
kamal kumar

Reputation: 53

Why my Selenium web driver is not clicking on Element identified by id?

My Selenium web driver is not clicking on this tree node. I don't know exactly what we say it tree node or something else so this is image and I highlighted the element.

enter image description here

This right arrow part on which I want to click

And this is my code:

//wait.until(ExpectedConditions.elementToBeClickable(By.id("iconDiv"))); 
WebElement taskdropElementid = driver.findElement(By.id("iconDiv"));
System.out.println(taskdropElementid.getAttribute("class"));
if(taskdropElementid.getAttribute("class").equals("RightArrow")) 
  taskdropElementid.click();

Printing statement is giving me output dropdown. I think it should give RightArrow and when I am uncommenting wait part then it is continuously wait for the element to be clickable.

What am I doing wrong?

Upvotes: 1

Views: 78

Answers (1)

Saurabh Gaur
Saurabh Gaur

Reputation: 23815

Printing statement is giving me output dropdown

That means there are multiple elements with the same id iconDiv and unfortunately you're locating other element instead which has class name dropdown.

If you want to locate element with class name RightArrow, You should try using By.cssSelector() to locate it uniquely as below :-

WebElement taskdropElementid = driver.findElement(By.cssSelector("div#iconDiv.RightArrow"));
taskdropElementid.click();

Upvotes: 1

Related Questions