HTML in SFDC:

<a href="#" style="text-decoration:none;" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('j_id0:j_id1'),'j_id0:j_id1:j_id3:j_id4:j_id5,j_id0:j_id1:j_id3:j_id4:j_id5','_parent');}return false" class="btn">Choose Price Book</a>

My code:

WebDriverWait wait = new WebDriverWait(driver, 40);
             wait.until(ExpectedConditions.visibilityOfElementLocated(By
                         .xpath("//a[contains(text(),'Choose Price Book')]")));

     driver.findElement(By.xpath("//a[contains(text(),'Choose Price Book')]")).click();

Error:

EnabledException in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //a[contains(text(),'Choose Price Book')] (tried for 40 second(s) with 500 milliseconds interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:113) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:283) at AutomationOpportunityQuoteModule.TC_OpptyQuoteFF.main(TC_OpptyQuoteFF.java:51) Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //a[contains(text(),'Choose Price Book')]

Any advice guys?

Screenshot in View page source: View Page source

When Manually type XPATH Manual XPATH

New contributor
user10426857 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Add screen-shot on fail to your code. Lets check if it is really visible. – Alexey R. Oct 11 at 10:56
  • Is it located inside an IFRAME? – Bill Hileman Oct 11 at 13:58
  • Can you locate the element manually with that xpath in chrome using developer tools? – Bill Hileman Oct 11 at 14:00
  • @BillHileman yes, sometimes it works and sometimes not when i tried to refresh the page. Regarding IFRAME, i think it is not in the IFRAME – user10426857 Oct 11 at 20:05

Your Answer

user10426857 is a new contributor. Be nice, and check out our Code of Conduct.
 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.