单击使用硒无法选择的字段名称 [英] Clicking on a field name whose unselectable is on using Selenium

查看:66
本文介绍了单击使用硒无法选择的字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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')]")));

这篇关于单击使用硒无法选择的字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆