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,320 points
10,426 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,

Hope this will solve your problem.

To know more about Angular, I would recommend you to join Angular online course today.

Thanks.

answered Jun 18, 2018 by Samarpit
• 5,910 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

I am getting Stale element exception when I try to automate angular js - drop down using Selenium with Java

Hey @Dhivya, StaleElementReferenceException is thrown when an ...READ MORE

answered Feb 12, 2020 in Selenium by Sirajul
• 59,230 points
3,173 views
+1 vote
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 4, 2020 in Selenium by Sri
• 3,190 points
26,658 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,500 points
12,616 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,571 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,910 points
6,629 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 3, 2020 in Selenium by Sri
• 3,190 points
7,517 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
14,421 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,910 points
6,885 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP