<a href="eventLog.cgi?command=0" target="content" class="Menu_titleFont">View Event Log</a>
如何在selenium
中点击“查看事件日志”
?
我已经尝试过
By.CssSelector("a[href^='eventLog.cgi?command=0']")
但是发生了“NoSuchElementException 未处理”
错误。
最佳答案
您可以尝试等待DOM
中出现元素,如下所示:
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.CssSelector("a[href='eventLog.cgi?command=0']")));
或
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementExists(By.LinkText("View Event Log")));
如果您的元素位于 iframe
内,您可能需要使用
webDriver.SwitchTo().Frame("menu");
搜索元素之前
关于c# - 如何通过Selenium点击链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868910/