如何单击< a>锚标签链接仅知道其硒C#的跨度
在网页上,我想使用硒单击此锚点:
<a onclick='ejecutaOpcion(this, '/srDocumentoAdmRecepcion.do?accion=goInicioGet&estadoDoc=01&coDep=10016','POST');' class='menu_lista' href='#'>
<span>Recepción de Documentos</span>
</a>
该锚点和类“菜单_lista”没有ID或名称,用于同一网页中的其他锚。
我尝试过:
var recepcionLink = myWebDriver.FindElement(By.XPath("//a[@class='menu_lista']/span[text()='Recepción de Documentos']"));
recepcionLink.Click();
但是,我有例外:
OpenQA.Selenium.ElementNotInteractableException:'element不相互作用(会话信息:chrome = 103.0.5060.53)'
看起来我正在获取跨度元素,而不是锚定元素。
On a web page there is this anchor that I want to click using Selenium:
<a onclick='ejecutaOpcion(this, '/srDocumentoAdmRecepcion.do?accion=goInicioGet&estadoDoc=01&coDep=10016','POST');' class='menu_lista' href='#'>
<span>Recepción de Documentos</span>
</a>
There is no Id or Name for that anchor and class "menu_lista" is used for other anchors in same web page.
I've tried:
var recepcionLink = myWebDriver.FindElement(By.XPath("//a[@class='menu_lista']/span[text()='Recepción de Documentos']"));
recepcionLink.Click();
However, I got exception:
OpenQA.Selenium.ElementNotInteractableException: 'element not interactable (Session info: chrome=103.0.5060.53)'
It looks like I'm getting the span element but not the anchor element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用linkText。
You can try using linktext.
尝试使用相对定位器(Selenium 4中的新定位器)
文档
https:// https://www.selenium.selenium.dev/dev/documentation/webdriveration/webdriveration/webdriveration/webdriveration> /elements/loadators/#可用的销售量
Try using relative locators (new in Selenium 4)
Docs
https://www.selenium.dev/documentation/webdriver/elements/locators/#available-relative-locators