c# - 如何通过Selenium点击链接?

标签 c# selenium-webdriver automated-tests

<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/

相关文章:

java - 如何根据枚举列表值运行每个浏览器驱动程序?

testing - SAUCE_CONFIG_PATH 在 testcafe-browser-provider-saucelabs 中对我不起作用

java - 如何将调用带有身份验证的Post请求的C#代码转换为Java?

c# - 在执行 C# 自定义 Cmdlet 期间收集用户输入(不通过参数)

python - Selenium 查找按钮元素

symfony - 并行运行行为测试(在两个浏览器窗口中)

java - Selenium Chrome 屏幕截图 - html2canvas

java - 如何从 Cucumber-java 中的日期选择器中选择值

c# - 调用 MessageBox 和 BeginInvoking 有什么区别?

c# - Windows Phone 中的 "Operation not permitted on IsolatedStorageFileStream"问题