0

Having difficulty to select a item from drop down. HTML:

<div id="first4" class="ui-small ui-re-row-sapce">                          
<select name="srclang" id="srclang" data-placeholder="Type source language *" class="form-control del-change capturedata selectized" tabindex="-1" style="display: none;"><option value="90" selected="selected">English</option></select>

<input type="select-one" autocomplete="off" tabindex="" id="srclang-selectized" placeholder="Type source language *" style="width: 151px; opacity: 1; position: relative; left: 0px;">

Code trials:

Select SourceLanguageIs= new Select(driver.findElement(By.xpath("//input[@id='srclang-selectized']"))); 
SourceLanguageIs.selectByIndex(2); 
//SourceLanguageIs.selectByVisibleText("English"); // 
SourceLanguageIs.selectByValue("90");
0

3 Answers 3

1

As per the HTML it seems the <select> node is having the attribute style="display: none;" so you can't directly access the <select> node.

You can pass the partial relevant character sequence i.e. English to the <input> tag and then click() on the element with text as English and you can use the following solution:

new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='srclang-selectized']"))).sendKeys("English");
new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[@id='srclang' and @name='srclang']/option[contains(., 'English')]"))).click();
Sign up to request clarification or add additional context in comments.

Comments

0

Ignore the Select class because the 'select' tag line is invisible and Try the below code:

driver.findElement(By.id('srclang-selectized')).sendKeys("Option that you want to Select");

As it is an id so no need to write an XPath expression.

2 Comments

select is not an attribute, perhaps select node.
@DebanjanB, Yeah, it is a tag.
0

The following are the most common methods used on to select drop down list.

  1. selectByVisibleText()
  2. selectByValue()
  3. selectByIndex()

Sample code to select the drop down as follows:

Select SourceLanguageIs= new Select(driver.findElement(By.id("srclang")));
SourceLanguageIs.selectByIndex(2); 
SourceLanguageIs.selectByVisibleText("English");
SourceLanguageIs.selectByValue("90");

Hopes it helped out .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.