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,330 points
4,706 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,890 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
0 votes
2 answers

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

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 3 in Selenium by Sri
• 2,970 points
15,059 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

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,510 points
3,531 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,535 views
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,890 points
2,596 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,863 views
+1 vote
2 answers

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

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

answered Nov 28, 2018 in Selenium by Rijhu mal
9,131 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,890 points
4,060 views