当前位置: 动力学知识库 > 问答 > 编程问答 >

Can't click to Customize link when div+link together with FakeAnchor class using selenium web driver

问题描述:

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?

Expected:

Clicking to Customize link should open respected option (it actually opens dialog).

Actual:

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.

Locator:

css=div[id$='_repeatDesc'][class='FakeAnchor']

Html:

<div id="zcs1_repeatDesc" class="FakeAnchor" style="cursor: pointer;">Customize</div>

Code:

webDriver().findElement(By.cssSelector("div[id$='_repeatDesc'][class='FakeAnchor']")).click();

网友答案:

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']")));
分享给朋友:
您可能感兴趣的文章:
随机阅读: