簡體   English   中英

Selenium Webdriver無法訪問Internet Explorer 8上的Web元素-顯示為已禁用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM