1

I have a link which is having the href attribute as javascript:void(0), but it is having the onclick function. In the onclick function dev is use to log the number of hits to be database through ajax calls and based on the ajax response they are redirecting to another URL.

The problem is that when I try to click on the above said link, it is not redirecting to any other URL and also not trapping any errors for click function. So I hope click() method executed successfully, but the page was not redirected to another URL. It is stopping me going further.

Any help or suggestions on this is appreciated.

HTML code:

<a href="javascript:void(0);" onclick="get_insert_update_click('http://www.samplewebsite.com/1250290CR','Showcase','1250290CR','CARS_PAGE','CAR_IN_FEATURED_CARS');" id="listing_image_290" name="listing_image_290" class="font_size_15"><img width="155" height="103" src="http://samplewebsite.com/public/uploads/processed/155x103-1409227190127_main_l.jpg" alt=""></a>

Sample Script to click on link:

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,800)");

wait.until(ExpectedConditions.elementToBeClickable(By.id("listing_image_290")));
try {
   driver.findElement(By.id("listing_image_290")).click();                                
} catch(Exception e){
    System.out.println("error");  
    e.printStackTrace();
}
  • Did you try to use try , catch to get error info? Also please share html and web driver code. – Helping Hands Jun 4 '15 at 5:47
  • Hello Helping Hands , I have updated my question .Please check and also I am not getting any errors even I am using try catch blocks also – QAMember Jun 4 '15 at 5:57
  • Did ur scroll works properly ? – Sagar007 Aug 17 '18 at 7:36
2

I dont see "title_link_1013" in your HTML code, how should it find your <a> ? Maybe use the ID instead?

driver.findElement(By.id("listing_image_290")).click(); 
  • Sorry by mistake I have pasted wrong Id here, But I am trying with the correct iD – QAMember Jun 4 '15 at 8:00
  • This should work. – GuardTheGates Jun 5 '15 at 12:31
0

Understand there could be an issue with the browser preferences. If the browser preferences / options are set to block the popup's then the re-directing link may not be working.

I will recommend to try with below code:

System.setProperty("webdriver.chrome.driver",<ChromeDriverPath>);

ChromeOptions chromeOptions = new ChromeOptions();

Map<String, Object> prefs = new HashMap<String, Object>();

prefs.put("profile.default_content_settings.popups", 0);

prefs.put("download.prompt_for_download", true);

chromeOptions.setExperimentalOption("prefs", prefs);

driver = new ChromeDriver(chromeOptions);

driver.findElement(By.id(<linkID>)).click

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.