[英]Selenium Webdriver unable to access web element on Internet Explorer 8 - shown as disabled
Setup Details: Webdriver 2.39 IEDriverServer 2.39 设置详细信息:Webdriver 2.39 IEDriverServer 2.39
I'm running Selenium automation on an internal site. 我正在内部站点上运行Selenium自动化。 The code works fine on Firefox 27 but there's an issue on IE8
该代码在Firefox 27上运行良好,但IE8上存在问题
I'm trying to first clear and enter text in a text field on IE. 我正在尝试先清除并在IE上的文本字段中输入文本。 This fails on IE with the error "Element must not be hidden, disabled or read-only."
这在IE上失败,并显示错误消息“元素不得隐藏,禁用或只读”。 I checked the element properties on IE and it does indeed show enabled as False, even though the element is plainly available.
我检查了IE上的元素属性,即使该元素明确可用,它的确显示为False。 On Firefox, enabled is correctly set to True.
在Firefox上,enabled已正确设置为True。
I've tried to use Xpath and sendkeys but they don't work. 我尝试使用Xpath和sendkeys,但是它们不起作用。 Here what I tried:
这是我尝试的:
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
Is there some way I can access this element on IE? 有什么方法可以在IE上访问此元素?
Thanks, J. 谢谢,J。
We frequently test against IE8 and encounter "unique" Selenium issues. 我们经常对IE8进行测试,并遇到“独特的”硒问题。
Sometimes we use ExecuteScript
to bypass Selenium's finicky selectors, and use jQuery to return the element or to manipulate it directly: 有时我们使用
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('');");
The best solution was the builder object of Selenium. 最好的解决方案是Selenium的生成器对象。 I used this to force the automation to select the textbox and enter test like so:
我用它来强迫自动化选择文本框并输入test,如下所示:
IWebElement searchField = Global.driver.FindElement(by);
builder.Click(searchField).SendKeys(searchField, textToEnter).Perform();
This worked! 这工作了! J.
J.
WebElement searchField = Global.driver.FindElement(by);
builder.Click(searchField).SendKeys(searchField, textToEnter).Perform();
****its working but sending wrong text to the field. ****其工作正常,但向该字段发送了错误的文本。 For ex: i have to send "11-12-2015" and it is sending "28-12-2015".
例如:我必须发送“ 11-12-2015”,并且发送“ 28-12-2015”。 Any Clue what's happening when performing inserting action.****
任何提示执行插入操作时发生了什么。****
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.