I am new to selenium , currently am working on selenium webdriver i want to select a value from the drop down. The id=periodId and the option is many in that am trying to select Last 52 weeks.
Here is the HTML code:
<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>
</select>
Please suggest me some ways to click the drop down.
I tried with the above example lines but am getting error such as Element is not currently visible and so may not be interacted with Command duration or timeout: 32 milliseconds the drop downs values are the jquery multiselect widget format.
This question is related to
java
selenium-webdriver
Try this-
driver.findElement(By.name("period")).sendKeys("Last 52 Weeks");
If you want to write all in one line try
new Select (driver.findElement(By.id("designation"))).selectByVisibleText("Programmer ");
Actually select
does select but not placing the selected values to the respective field . Where wondered the below snippet works perfectly
driver.findElement(By.name("period")).sendKeys("Last 52 Weeks");
First Import the package as :
import org.openqa.selenium.support.ui.Select;
then write in single line as:
new Select (driver.findElement(By.id("sampleid"))).selectByValue("SampleValue");
As discussed above, we need to implement Select Class in Selenium and further we can use various available methods like :-
code to select dropdown using xpath
Select select = new
Select(driver.findElement(By.xpath("//select[@id='periodId']));
code to select particaular option using selectByVisibleText
select.selectByVisibleText(Last 52 Weeks);
I have not tried in Selenium, but for Galen test this is working,
var list = driver.findElementByID("periodID"); // this will return web element
list.click(); // this will open the dropdown list.
list.typeText("14w"); // this will select option "14w".
You can try this in selenium, the galen and selenium working are similar.
WebDriver driver = new FirefoxDriver();
WebElement identifier = driver.findElement(By.id("periodId"));
Select select = new Select(identifier);
select.selectByVisibleText("Last 52 Weeks");
You can use following methods to handle drop down in selenium.
For more details you can refer http://www.codealumni.com/handle-drop-selenium-webdriver/ this post.
It will definately help you a lot in resolving your queries.
Source: Stackoverflow.com