单击使用硒无法选择的字段名称

编程入门 行业动态 更新时间:2024-10-27 14:21:25
本文介绍了单击使用硒无法选择的字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图单击一个完全不可单击的字段.我要附上屏幕截图.

I am trying to click on a field which is exactly not clickable. I am attaching the screenshot of the screen.

页面后面的HTML代码是:

The Html code behind the page is:

<td class="x-grid3-col x-grid3-cell x-grid3-td-TRAVNAME " style="width: 234px;" tabindex="0"> <div class="x-grid3-cell-inner x-grid3-col-TRAVNAME" unselectable="on">ARUNACHALAM/SHAN</div> </td>

我编写的代码是用C#编写的,如下所示:

The code that I have written is in C# which is as follows:

Thread.Sleep(1000); Driver.Instance.FindElement(By.XPath("//*[@id='ext - gen13']/div/table/tbody/tr/td[3]/div")).Click();

抛出异常,表明无法找到该字段.

Its throwing exception saying it is unable to find the field.

有人可以帮忙吗?

推荐答案

尝试使用WebDriverWait如下:-

var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20)); var el = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("td.grid3-td-TRAVNAME div.x-grid3-col-TRAVNAME"))); el.Click();

已编辑:如果很遗憾由于unselectable="on"而无法单击,请在使用IJavascriptExecutor进行单击之前删除此属性属性,如下所示:-

Edited : If unfortunately it's not clickable due to unselectable="on", remove this attribute property before clicking using IJavascriptExecutor as below :-

var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20)); var el = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("td.grid3-td-TRAVNAME div.x-grid3-col-TRAVNAME"))); IJavaScriptExecutor js = Driver.Instance as IJavaScriptExecutor; el = (IWebElement)js.ExecuteScript("arguments[0].removeAttribute('unselectable'); return arguments[0];", el); el.Click();

已编辑:-cssSelector在这里不起作用,请尝试使用By.Xpath(),如下所示:-

Edited :- cssSelector does not work here try using By.Xpath() as below :-

var el = wait.Until(ExpectedConditions.ElementIsVisible(By.Xpath(".//div[contains(text(), 'ARUNACHALAM/SHAN')]")));

更多推荐

单击使用硒无法选择的字段名称

本文发布于:2023-11-27 20:40:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   单击   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!