Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
891 views
by Contributing Tester (53 points)
retagged by

Hello, I am facing next problem. I use selenium and Firefox and I need to click link here's example of code:

<a class="link-title" href="javascript:void(0)"><span class="bold">Rand Paul warns Republicans not to repeal-and-delay Obamacare</span></a>

I can use method "find_element_by_class_name('link-title')" to choose element and than call method click() but looks like it doesn't work. So is it possible to do it or not? 

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer
Usually when JavaScript is called, it makes Ajax call for your link. Do you want to try using WebDriverWait and wait for the next element?

Eg.

You click on the link. Wait for element you are expecting to be changed or appear. And perform your next operation.
by Contributing Tester (53 points)
Okay but it doesn't work. In my Firefox when I click that link it takes me to new web-page, in selenium nothing happens. I have compared page_source before click and after click, the page source is the same.
by
Try clicking using Actions class.

WebElement link= driver.findElement(By.linkedText("Linked text here"));
Actions ob = new Actions(driver);
ob.click(link);
Action action  = ob.build();
action.perform();
by Contributing Tester (53 points)
Thanks, I'll try.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...