Select a drop down value of angular js application using selenium using text

0 votes

Please see the html source of drop down 

Below is my function to select a value from a dropdown of angular js application

public String dropdownwithstringselect(String locatorName1,String locatorName2,String strtext)

    {

      try

      {

        wait(2);

        waitForElement(locatorName1);

        String locatorValueFromXML1 = utils.getLocatorData(locatorName1);                 

        WebElement sourceElement = driver.findElement(getElement(locatorValueFromXML1));

        sourceElement.click();

        String locatorValueFromXML2 = utils.getLocatorData(locatorName2);                 

        WebElement sourceElement1 = driver.findElement(getElement(locatorValueFromXML2));

        sourceElement1.getAttribute(strtext);

        extentTest.get().pass("Attribute value fetched from " + locatorName1);

      }

      catch (Exception e)

      {          

        extentTest.get().fail("Element - " + locatorName1 + " was not found");

        takeScreenShot();

      }

      return strtext;

    }
Jun 18, 2018 in Selenium by Martin
• 4,220 points
2,419 views

1 answer to this question.

0 votes

To select drop down use following,

driver.findElements(By.className("Your dropdown class - ui-dropdown-items-wrapper")).click;

If drop down is taking time, retrieve above in web element for the click event. After that You can retrieve label value with the following syntax: //span[contains(text(), "Your key value - Weekly Review")] You can manage Key value with dynamic variable also,

answered Jun 18, 2018 by Samarpit
• 5,130 points
Hi,

Using

bond_watchlist = driver.find_element_by_xpath("//textarea[@placeholder='Select or search...']")
bond_watchlist.click()

#this opens a dropdown.

driver.find_element_by_xpath("//li[@id='typeahead-18-6837-option-1']//div[@class='watchlist-option watchlist-option-tickers'][contains(text(),'P1')]").click()

The option-1 is dynamically given and keeps changing. And when I run this, it gives an invalid or illegal selector error.

Hi @x_Coder, try using ExpectedConditions.visibilityOfElementLocated() or ExpectedConditions.elementToBeClickable() methods to let the dynamic element load properly.

Related Questions In Selenium

0 votes
1 answer

Is it possible to manually set the attribute value of a Web Element using Selenium?

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,650 points
7,088 views
0 votes
1 answer
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,110 points
1,013 views
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
1,156 views
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
894 views
+1 vote
2 answers

Drop-down menu option value not working using Selenium (Python)

from selenium.webdriver.support.select import Select inputElementGa ...READ MORE

answered Nov 28, 2018 in Selenium by Rijhu mal
5,374 views
0 votes
1 answer

How to click a span with given text using Selenium Python

If ALL_USA is subject to change, then ...READ MORE

answered Jul 26, 2018 in Selenium by Samarpit
• 5,130 points
2,090 views