我试图单击一个完全不可单击的字段.我要附上屏幕截图.
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')]")));更多推荐
单击使用硒无法选择的字段名称
发布评论