Quality is delighting customers
I am new to selenium web driver I am creating script for a form which has multiple drop down in single page.i am not able to select the from drop down,suggest how can I select values from drop down list.
After inspecting an drop down this code only i am getting,
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-5" id="s2id_autogen5_search" placeholder="" aria-activedescendant="select2-result-label-14">
i tired this script in java but it's not working
driver.findElement(By.name("department");
driver.findElement(By.name("department")).sendKeys("accounts");
Tags:
Hi,
There are 3 types of Drop down.
1) select By Value
2) select By Index.
3)select by visible text.
Based on these Categories, u can select he dropdown Easily.
For Eg. In case u want to select the Third option in Dropdown out of Four Drop dopwn list means, u want to count the Order From Last to First. So u can use the Drop down Index as" driver.FindElement(By.name("department")).selectbyindex(2);
Hi Gokul,
Thanks for ur reply.
I used first method "select by value",
WebElement element = driver.findElement(By.id("department"));
Select se1 = new Select(element);
se1.selectByValue("14");
This code working fine now...
Hi,
If your asking about select an item from auto suggestion list means use the below process......
public void test() throws Exception{
WebElement textBoxElement = driver.findElement("---");
textBoxElement.sendKeys("a");
Thread.sleep(3000);
String OptionName = "JavaScript";
selectOptionWithText(OptionName);
}
public void selectOptionWithText(String texttoSelect) {
try{
WebElement autoOptions = driver.findElement(By.id("----"));
wait.until(ExpectedConditions.visibilityOf(autoOptions));
List<WebElement> OptionsToSelect = autoOptions.findElements(By.tagName("li"));
for(WebElement Option: OptionsToSelect){
if(Option.getText().equalsIgnoreCase(texttoSelect)){
System.out.println("Trying to select" + texttoSelect );
Option.click();
break;
}
}
}
catch(NoSuchElementException e){
System.out.println(e.getStackTrace());
}
catch(Exception e){
System.out.println(e.getStackTrace());
} }
use this one and modify it as you like...i think this will help full to u .....correct me if am wrong.....
Hi,
Method 1-
new Select(driver.findElement(By.id("collegeId"))).selectByVisibleText("DAV College");
[Here 'collegeId' is your dropdown's id. 'DAV College' is your dropdown value to be selected. You can use other methods also to select the dropdown value like - 'selectByValue' etc..]
Method 2-
Creating the Select object first then using it-
Select drop_con = new Select(driver.findElement(By.id("countryId1"))); // Replace "countryId1" with your dropdown id
drop_con.selectByVisibleText("INDIA"); // Replace 'INDIA' with your value
Method 3-
Using JavascriptExecutor-
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('countryId1').style.display='block';");
new Select(driver.findElement(By.id("collegeId"))).selectByVisibleText("INDIA");
Finally you can use 'WAIT' if required.
© 2022 Created by Quality Testing.
Powered by