[英]Selenium Webdriver unable to access web element on Internet Explorer 8 - shown as disabled
设置详细信息:Webdriver 2.39 IEDriverServer 2.39
我正在内部站点上运行Selenium自动化。 该代码在Firefox 27上运行良好,但IE8上存在问题
我正在尝试先清除并在IE上的文本字段中输入文本。 这在IE上失败,并显示错误消息“元素不得隐藏,禁用或只读”。 我检查了IE上的元素属性,即使该元素明确可用,它的确显示为False。 在Firefox上,enabled已正确设置为True。
我尝试使用Xpath和sendkeys,但是它们不起作用。 这是我尝试的:
driver.FindElement(By.XPath("//input[@name='tagName']")).Clear(); - not working
driver.FindElement(By.XPath("//input[@name='tagName']")).SendKeys(tagName); - not working
driver.FindElement(By.Id("tagName")).SendKeys(Keys.Control); - not working
driver.FindElement(By.Id("tagName")).Clear(); - not working
driver.FindElement(By.Id("tagName")).SendKeys(tagName); - not working
有什么方法可以在IE上访问此元素?
谢谢,J。
我们经常对IE8进行测试,并遇到“独特的”硒问题。
有时我们使用ExecuteScript
绕过Selenium的挑剔选择器,并使用jQuery返回元素或直接操作它:
// Get an element
IWebElement element = (IWebElement) driver.ExecuteScript("return $('#tagName')[0]");
// Clear the value of a field
driver.ExecuteScript("$('input[name=\'tagName\']').val('');");
最好的解决方案是Selenium的生成器对象。 我用它来强迫自动化选择文本框并输入test,如下所示:
IWebElement searchField = Global.driver.FindElement(by);
builder.Click(searchField).SendKeys(searchField, textToEnter).Perform();
这工作了! J.
WebElement searchField = Global.driver.FindElement(by);
builder.Click(searchField).SendKeys(searchField, textToEnter).Perform();
****其工作正常,但向该字段发送了错误的文本。 例如:我必须发送“ 11-12-2015”,并且发送“ 28-12-2015”。 任何提示执行插入操作时发生了什么。****
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.