Reputation: 4043
Can't click to Customize link when div+link together with FakeAnchor class using selenium web driver
In my Ajax application, we have dropdown + link (Customize) together in div and i want to click to Customize link. I have locator and which was working fine for Customize link with old selenium but it doesn't with latest web driver. Can anyone please point me the problem or suggest something to make it work?
Clicking to Customize link should open respected option (it actually opens dialog).
Below locator clicks to dropdown button instead of Customize link due to such a complex page DOM which has no actual href or anchor tag.
css=div[id$='_repeatDesc'][class='FakeAnchor']
<div id="zcs1_repeatDesc" class="FakeAnchor" style="cursor: pointer;">Customize</div>
webDriver().findElement(By.cssSelector("div[id$='_repeatDesc'][class='FakeAnchor']")).click();
Upvotes: 1
Views: 47
Reputation: 23805
I think your locator is not unique, may be it is locating dropdown element that's why it clicks to dropdown button instead of Customize link.
You should try using By.xpath()
with text()
node to locate this element as below :-
webDriver().findElement(By.xpath(".//div[text() = 'Customize']")).click();
Or As I'm seeing in HTML element has id
attribute, if it's unique I'd to locate desire element and it's not being changed dynamically, you can try also using By.id()
as below :-
webDriver().findElement(By.id("zcs1_repeatDesc")).click();
Edited :- If you want to click using JavascriptExecutor
try as below :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", webDriver().findElement(By.xpath(".//div[text() = 'Customize']")));
Upvotes: 1