4

I am trying to automate spicejet.com website, but the thing is I am not able to access the dropdown values using select as the dropdown values like destination, source etc are not in Select Option="value" format. When I try to work on using click and select the places it's not working as the click lands me in different page. and it's not only that, I have seen same pattern in many websites. using input field, buttons and lists instead of direct drop down lists.

  • 1
    Please show the exact HTML you are working with and also the code for the attempts you have made. Then we can advise better – Michael Durrant Apr 7 '16 at 11:11
  • What client for webdriver do you use? python/java/js? – bogdan.mustiata Apr 7 '16 at 16:32
1

Solution:

I have face this issue. Its really weird when all automation scripts and code written as per standards but ultimately it get failed. Below solution works for me:

Step 1.

WebElement listbox_webelement = drive.findElement(By.xpath("write_your_xpath_of_element"));

Step2.

listbox_webelement.click() [ Expected to list get visible ]

Step3.

Select select = new Select(listbox_webelement);

Step4.

select.sendKeys("Text_From_Your_Listbox");
              OR

Step4.

listbox_webelement.sendKeys("Text_From_Your_Listbox");
  • TrueAlpha - Your issue resolved or still facing it? – NarendraC Aug 8 '16 at 5:55
0

You are using Select class to manipulate an ul element (unordered list) and it will fail, as Select class was designed to cater select (i.e dropdowns) elements only.

Now to solve your problem statement, say I have to select Kochi(COK) from the list, follow the below steps :

  1. Do a sendkeys.

    driver.findElement(By.id("ctl00_mainContent_ddl_originStation1_CTXT")).sendKeys("COK");

  2. Now perform a click using linktext.

    driver.findElement(By.linkText("Kochi (COK)")).click();

Hope this helps.

0

As a matter of fact for drop down list, in Selenium we have Select class. To use this select class you have to use import statement-

import org.openqa.selenium.support.ui.Select

This Select class has several methods that are supported to access the elements.

  • ByVisibleText
  • ByIndex
  • By.Id
  • ByValue

Sample code:

Select dropDown1 = new Select(element1);            
dropDown1.selectByIndex(2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.