javascript - Select option from dropdown-element is not visible - Stack Overflow

Please anyone can help me how to select options from the drop down if the element is not visible. Here

Please anyone can help me how to select options from the drop down if the element is not visible. Here is the html tag:

<select id="visualizationId" style="width: 120px; display: none;" name="visualization">
<option value="day">Day</option>
<option value="week">Week</option>
<option selected="" value="month">Month</option>

Am working on selenium webdriver. the below code is not working fine. Is there any sample code to select the invisible element.

Actions actions1 = new Actions(driver);
WebElement dBox1= ((new WebDriverWait(driver,60)).until(ExpectedConditions.elementToBeClickable(By.id("visualizationId"))));
selectByVisibleText("week");
actions1.moveToElement(dBox1);
actions1.click();
actions1.perform();

When using the below lines also am getting the error: Element is not currently visible and so may not be interacted with Command duration or timeout: 32 millisecond

Select se=new Select(driver.findElement(By.id("visualizationId")));
se.selectByVisibleText("Week");

or

se.selectByValue("week");

Please see the html and there the element is not visible. Can any one suggest me how to make element visible and select the option.

Please anyone can help me how to select options from the drop down if the element is not visible. Here is the html tag:

<select id="visualizationId" style="width: 120px; display: none;" name="visualization">
<option value="day">Day</option>
<option value="week">Week</option>
<option selected="" value="month">Month</option>

Am working on selenium webdriver. the below code is not working fine. Is there any sample code to select the invisible element.

Actions actions1 = new Actions(driver);
WebElement dBox1= ((new WebDriverWait(driver,60)).until(ExpectedConditions.elementToBeClickable(By.id("visualizationId"))));
selectByVisibleText("week");
actions1.moveToElement(dBox1);
actions1.click();
actions1.perform();

When using the below lines also am getting the error: Element is not currently visible and so may not be interacted with Command duration or timeout: 32 millisecond

Select se=new Select(driver.findElement(By.id("visualizationId")));
se.selectByVisibleText("Week");

or

se.selectByValue("week");

Please see the html and there the element is not visible. Can any one suggest me how to make element visible and select the option.

Share Improve this question edited Dec 4, 2013 at 5:39 HemChe 2,3371 gold badge22 silver badges34 bronze badges asked Dec 4, 2013 at 4:13 testingtesting 1,79615 gold badges46 silver badges75 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 2

Here, for selecting option, I'm trying to click on element using javascript(javascript because it allows you to interact with hidden elements). Following is the code, give a try. I'm not sure about the code and syntax(I'm not java guy), still you can use logic.

WebElement elementToSelect = driver.findElement(By.xpath(".//select[@id='visualizationId']/option[text()='Day']")

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", elementToSelect);

You don't need the ="", just selected will work fine

Also, how are you supposed the select from a dropdown that isn't visible? There will be nothing to click

The selected attribute is a boolean attribute. The syntax is <option selected>. So Just try this without ""

<option value="month" selected>Month</option>

try this code

Select se=new Select(driver.findElement(By.id("visualizationId")));

se.selectByVisibleText("week")

my bad its typo mistake misplaced "w" with "W" please try this

Select se=new Select(driver.findElement(By.id("visualizationId")));

se.selectByVisibleText("Week");

or

se.selectByValue("week");

You can only interact with elements that are visible on the webpage. You can surely get the not visible element (or parts of it), but you can't do anything with it. If you want to interact with this Select element, you first need to make sure it's visible (display attribute of the Select element) so you can interact with it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395284a4625849.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信