0

enter image description here

HTML:

<a href="https://stgtest.flexforceondemand.com/associateregistration/consenttoproceed?bid=U20xNFozbFBkV0pFZWpWWlpGRjRVMUZJZUVwWFFUMDlPanBnTHhJRmY4R1VRWVh6aFVHN2swcW0%2A&amp;zc=VkdSdVVGZHRTbEZVY3pkWFRYZGFkRTVTUVhFclp6MDlPanJFTUVSazZNV0ErYTdlZ0ovR1BhWng%2A" class="btn btn-success btn-lg">Apply Now</a>

I have already tried the following:

driver.findElement(By.xpath("//a[text()='Apply Now']")).click();
driver.findElement(By.xpath("(.//[@href='Apply Now'])")).click();
driver.findElement(By.xpath("//a[@href='Apply Now']")).click();
driver.findElement(By.linkText("Apply Now")).click();
driver.findElement(By.className("Apply Now")).click(); 
driver.findElement(By.xpath("//div[contains(@class,'btn btn-success btn-lg')]")).click();
driver.findElement(By.xpath("//div[contains(@class,'btn btn-success btn-lg')]")).click();v
Guy
  • 46,488
  • 10
  • 44
  • 88
Ganesh
  • 1
  • 2

4 Answers4

1

Try to click with webdriver wait till element is properly loaded in Dom and ready to receive click.

WebDriverWait wait = new WebDriverWait(driver, 40);

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.='Apply Now']"))).click();
Muzzamil
  • 2,823
  • 2
  • 11
  • 23
0

Option 1 Try By.CssSelector Option 2 Not sure if you are checking if element is exists before clicking on it.if not then use wait.until. If possible paste error you are getting here. Hope this helps.

Amruta
  • 1,128
  • 1
  • 9
  • 19
0

The desired element is a dynamic element so to locate and click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • linkText:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Apply Now"))).click();
    
  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.btn.btn-success.btn-lg[href*='associateregistration']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='btn btn-success btn-lg' and contains(@href, 'associateregistration')][text()='Apply Now']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try this please, maybe it will help

driver.findElement(By.id("select2-section-tn-container")).click();