How to create a Javascript executor for making an element visible in Selenium Webdriver?

0 votes

Currently, I am working on Selenium Webdriver. I have many dropdowns like visualization, period, type, etc. These dropdowns contain many options and I want to select an option from it and my target is to find an element through its ID.

But, in the HTML tag, the element is not visible to select an option. I tried verifying by putting across a lot of questions and most of them are suggesting to use the Javascript executor.

Can anyone please help me the javascript for the HTML tag:

<select id="periodId" name="period" style="display: none;">
<option value="l4w">Last 4 Weeks</option>
<option value="l52w">Last 52 Weeks</option>
<option value="daterange">Date Range</option>
<option value="weekrange">Week Range</option>
<option selected="" value="monthrange">Month Range</option>
<option value="yeartodate">Year To Date</option>
Mar 26 in Selenium by Vaishnavi
• 860 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hey there,
You can try using the following script to make an element visible: 


In Java code this script can be executed with the following snippet:

JavascriptExecutor executor = (JavascriptExecutor)driver;

And if you just want to select an option in the dropdown you can use the following java code:

Select select = new Select(driver.findElement("periodId")));
select.selectByVisibleText("Last 4 Weeks")

Hope this is helpful.

answered Mar 26 by Surya
• 860 points

Related Questions In Selenium

0 votes
1 answer

How to use JavaScript in selenium to click an Element?

Executing a click via JavaScript has some ...READ MORE

answered Apr 13, 2018 in Selenium by Shubham
• 12,790 points
+4 votes
3 answers

Verifying whether an element present or visible in selenium Webdriver

Below code will help you: To check Element ...READ MORE

answered Apr 17, 2018 in Selenium by king_kenny
• 3,590 points
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How can I delete an element in Selenium using Python?

Hi friend, getElementByClassName is not a method on ...READ MORE

answered Mar 26 in Selenium by Surya
• 860 points

edited Mar 27 by Omkar 173 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.