当前位置: 动力学知识库 > 问答 > 编程问答 >

selenium - Element is not currently visible and so may not be interacted with

问题描述:

Currently i am trying to parse a sample site.

In that site there is a which set to "display :none"

in order to apply css effects. I mean in fact that select

component is visible.

How can i set value to that html select component ?

Here is my code :

 WebElement element = driver.findElement(By.name("paper"));

Select paperList = new Select(element);

paperList .selectByValue("73"); // it gives error

driver.findElement(By.className("btn1")).click();

I am using Java + Selenium WebDriver 2.0

Here is the exception :

Caused by: org.openqa.selenium.remote.ErrorHandler

$UnknownServerException: Element is not currently visible and so may

not be interacted with Build info: version: '2.14.0', revision:

'unknown', time: '2011-11-29 13:13:16' System info: os.name: 'Windows

XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0-ea'

Thanks.

网友答案:

Well there are two different ways to handle this that I can think of. First clean up the css on the page so that you don't have two conflicting styles on the same element. Second my guess is you have some form of javascript enabling the select menu which is probably firing after your selenium test grabs the object and says that it's not visible. Try dropping a thread.sleep before you grab the code, just for testing purposes. If that resolves the issue then I would create a javascript that would look for document.readyState and if it were "complete" then I would start parsing the page with Selenium.

------ EDIT ------

Well to modify the DOM with selenium you need to use the JavascriptExecutor class and cast it to your WebDriver. After you do that then you can execute javascript from your selenium application on the page which means you can manipulate the DOM.

Here's an example:

WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('//elementID').removeAttr('display');");

http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions

http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html

网友答案:

Find the UI element exactly with all the //div attributes helped me to locate element in every run. Include all attributes to find element like class name, text, style etc.

网友答案:

please update your selenium stand alone server to 2.35.0 or more if available. the jar file needs to be updated. I had the same issue and I was using jar file version 2.33.0 and as soon as I updated /downloaded the new selenium stand-alone-server jar file of 2.35.0 , it solved my issue.

分享给朋友:
您可能感兴趣的文章:
随机阅读: