Reputation: 31
I am using WebDriver API to test a webpage and the click()
method is not working on a particular webpage.
Neither it is showing any exception nor clicking on the webelement (a link in my case). I tried to find the element using xpath, id and link but the click did not work.
However, when I tried contextClick
(i.e. right click) operation on the same link, it worked. Also when I print the text or tagName
of the web-element, the text or tagName is displayed perfectly fine on the output screen.
My code:
WebDriver browser=new InternetExplorerDriver();
browser.get("some website");
WebElement linkkk=browser.findElement(By.xpath("//*[@id='topsort']/li[2]/a"));
linkkk.click();
web-page code:
<div class="content">
<div class="blind" style="display: none;"></div>
<ul id="topsort">
<li>something</li>
<li><a class="category_nav_remote_link selected" href="some website">some text</a></li>
</ul>
</div>
</div>
I even used:
Actions action=new Actions(browser);<br/>
action.click(linkkk);
action.perform();
But in vain.
Upvotes: 2
Views: 4768
Reputation: 4536
Try below options:
WebElement linkkk=browser.findElement(By.xpath("//*[@id='topsort']/li[2]/a"));
linkkk.click();
//click once again
linkkk.click();
OR - Try by sending ENTER key as below:
linkkk.sendKeys(Keys.ENTER);
OR - First move to that link & then click or send ENTER key
Actions moveTo = new Actions(driver);
moveTo.moveToElement(linkkk).click().perform();
Upvotes: 7
Reputation: 11
Try using IJavaScriptExecutor to click on the button. It's been very successful on my app.
((IJavaScriptExecutor)_webDriver).ExecuteScript("$(arguments[0].click()",webElement);
Upvotes: 1