c# - Click 事件不适用于 Button Sin Selenium
问题描述
直到昨天,我的代码一直在单击此按钮,但现在当我尝试使用相同的代码时,该按钮只是突出显示而没有被单击。已经尝试了所有可能的方法来通过在互联网上冲浪并找到解决方案来点击它,但没有任何效果。
IWebElement ele = river.FindElement(By.Id("btnToTranslate"));
IJavaScriptExecutor executors = (IJavaScriptExecutor)driver; executors.ExecuteScript("arguments[0].scrollIntoView()", ele);
ele.Click();
ele.SendKeys(Keys.Enter);//even tried sending enter button but nothing happens.
我要获取的元素是
先感谢您。
解决方案
我认为您需要使用显式等待等待,然后使用 Actions 类单击:
var element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.Xpath("//span[text()='Translate']")))
Actions actions = new Actions(driver);
actions.MoveToElement(element);
actions.Build().Perform();
推荐阅读
- ios - uitableviewcell 内的集合视图单元格中的图像不采用圆角
- angular - 是否可以覆盖 mat-datepicker 上的 mat-monthly-view 组件以添加周数列?
- gradle - 将 'settings.gradle' 中的 'project.hasProperty()' 从 groovy 翻译成 kotlin
- c# - 在 c# 中使用新的 GUID 克隆具有所有子节点的对象
- elasticsearch - 对同一个嵌套对象的两个查询..在不同的值上,然后期望 inner_hits 中有 2 个匹配的对象,但在 Elasticsearch 中只有 1 个
- cmd - 如何从 HTA 文件向同一个 cmd 实例发送多个命令?
- python - 如何在 Python 中将特殊字符写入 DBF 文件?
- javascript - 通过 JavaScript 在 HTML 中正确编码变体选择器
- javascript - 传单:如何删除多边形绘制控制下的“完成”、“删除最后一点”和“取消”子菜单?
- entity-framework - 通过其'列获取相关条目