-1

I wonder how I can use selenium to click on web element "automation_quiz" at this javascript:_doPostBack().

The following is a snippet from the html page:

<a id="ctl00_Content_tgv_ctl03_lbtCaption" title="click to launch automation_quiz" href="javascript:__doPostBack('ctl00$Content$tgv$ctl03$lbtCaption','')">automation_quiz</a>

I could not find the Xpath of "automation_quiz" by using firefox Xpath-finder.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
jeff_hqh
  • 1
  • 1

2 Answers2

-1

The desired element is a JavaScript enabled element so to Click() on the element you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies:

  • LinkText:

    new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.LinkText("automation_quiz"))).Click();
    
  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("a[title='click to launch automation_quiz'][href*='Content'][id$='lbtCaption']"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@title='click to launch automation_quiz' and text()='automation_quiz']"))).Click();
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-3

Unfortunately, you cannot find web elements by JavaScript methods initiated in their click with Selenium. Also unfortunate is that there is no current alternative to Selenium for navigating dynamic content. Check the documentation for other web element search methods. If you can’t find by Xpath, maybe you could locate using html ID or similar. If not, try using the ChromeDriver instead of Firefox. I’ve had much less trouble using Xpaths on chrome.

Dharman
  • 30,962
  • 25
  • 85
  • 135
A Bear
  • 59
  • 6