Yojana
Yojana

Reputation: 13

Selenium WebElement(Div)

My doubt is how to click/select Div elements in Selenium using java?

I tried like this:

String divId = driver.findElement(By.tagName("Div")).getAttribute("Div Value");
driver.findElement(By.id(divId)).click();

But in the above code im getting divId as NULL.Thats why im getting IlleagalArgumentsException.

Upvotes: 0

Views: 91

Answers (2)

Juhan
Juhan

Reputation: 1291

If your div is in a frame tag first just switch to that frame and do rest..

Switch to frame

Upvotes: 2

sol4me
sol4me

Reputation: 15698

In order to get id of the div Change

String divId = driver.findElement(By.tagName("Div")).getAttribute("Div Value"); 

to

  String divId = driver.findElement(By.tagName("div")).getAttribute("id"); 

Upvotes: 0

Related Questions