c# - 如何单击元素c#的中心?
问题描述
我对 selenium 和 c# 很陌生,单击此元素时遇到问题:
<i _ngcontent-ldd-c264="" class="close ms-icon iconms-cancel02 fixCloseModal">
<::before>
我试图用类和 xpath 找到元素,但是每当我尝试单击时,我都无法找到。
IWebElement CloseCard = driver.FindElement(By.ClassName("fixCloseModal"));
CloseCard.Click();
上面是尝试使用类名查找元素的示例。我得到这个异常:“OpenQA.Selenium.ElementNotInteractableException:'元素不可交互”。
用 chrome 检查,需要点击的按钮在"::before"
.
类前面的行突出显示可点击区域的轮廓。
如果问题不清楚,请道歉,如果我需要澄清,请告诉我。
解决方案
如果页面在重新渲染时正在移动,则可能会发生这种情况。显式等待可以帮助解决问题:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
var closeCard = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector(".fixCloseModal")));
closeCard.Click();
推荐阅读
- angular - FullCalendar 选择和拖放停止工作
- mysql - 显示用户未添加的好友列表
- c++ - CLion C++ 的许多未定义引用
- django - 为什么在尝试运行 Django 的 plesk 上出现 403 错误
- next.js - 有没有办法从java后端创建的url重定向到next.js中的reset-password页面?
- c++ - 如何在 C++ 中读取反斜杠作为字符串的一部分
- angular - 请启用 JavaScript 以继续使用此应用程序
- javascript - Oracle Apex 20.1 - 在经典报表中创建单选按钮并在项目中创建值
- acumatica - 在 Acumatica 图表上显示多条线
- ruby-on-rails - 如何从 ids Rails 数组列表中的产品中获取价格