Tamim
Tamim

Reputation: 73

How to click the link via Selenium?

<a href="eventLog.cgi?command=0" target="content" class="Menu_titleFont">View Event Log</a>

How to click the "view event log" in selenium? I have tried

By.CssSelector("a[href^='eventLog.cgi?command=0']")

but "NoSuchElementException was unhandled" error occured.

Upvotes: 2

Views: 184

Answers (1)

Andersson
Andersson

Reputation: 52665

You can try to wait until element is present in DOM as below:

WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.CssSelector("a[href='eventLog.cgi?command=0']")));

or

WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.LinkText("View Event Log")));

If your element located inside iframe, you might need to use

webDriver.SwitchTo().Frame("menu");

before searching for element

Upvotes: 2

Related Questions