0

I am new to Selenium Webdriver , I have an application build in angular 2 and trying to select values in drop down which are mandatory.

1) Select a value from a dropdown; initially the dropdown is red in color (red is the requirement).

2) As soon as a value is selected from the dropdown the border color of the dropdown should be blue.

I am able to select values successfully from dropdown however the color is still remaining red and not changing to blue please suggest why?

Select Speciality_dd = new Select(driver.findElement(By.name("boardCertificationSpeciality0")));
                                      Speciality_dd.selectByVisibleText("Addiction Medicine");
                                      Thread.sleep(1000);
0

What is the behavior during manual testing? And I would suggest to change the focus of webdriver to somewhere else(for example by clicking or writing in another text box or clicking on another button) then check the color of the drop-down list again. If it did not work, I would suggest to report it as a bug to developers.

  • Thanks Jose for your quick reply.During manual testing , the color changes from red to blue when a value is selected.In my application i have a lot of other fields like text boxes ,radio buttons and drop downs. The color changes from red to blue in few dropdowns but for other drop downs the color does not change and it remains red.I am not sure why it works for the few drop downs and not the others even though the code is same throughout.I tried changing the focus of webdriver to somewhere else, added a delay , the way of selection like by text , or id...still the result is the same . – Radhika Nov 11 '16 at 15:38
  • 1
    Strange! I wish I could check HTML of these different drop-boxes. But I still think you should share this strange behavior with development team and I wish you good luck! – Jose Nov 14 '16 at 10:25
0

This happens many times when selection is happening instantly.

For this you can try following handy tricks:

  1. Select dropdown item and add a wait event. So that during wait time the field becomes normal and accepts the input selected.

  2. Select dropdown item and then click on body of page( I know it might sound silly, but you can try in order to shift focus).

  3. Select dropdown item and explicitly put focus on next field which you are going to input value, even though the focus will be shifted automatically but when you add explicit shifting of focus the previous field will possibly become normal.

Also try by selecting dropdown item by using index instead of text. Looping through dropdown items using index and inside loop, add if condition dropdown item's text matches with your string and make it select that item if it matches.

  • I tried pt. no 1,2 and also selecting the dropdown using index and value.Nothing seemed to work.Can u please explain what u mean by pt.3? I am very new to selenium , so not sure what u mean by pt 3.Also if u can give an example by code for 'Looping through...'Thanks for ur suggestions – Radhika Dec 1 '16 at 16:55
  • IWebElement fruits =browser.FindElement (By.XPath (".//*[@id='ddlFruits']")); fruits.Click(); for (int i = 0; i < fruits.Options.Count; i++) { string fruitTobeSelected= InvTPOfield ().Options [i].GetAttribute ("text"); if (fruitTobeSelected.Contains ("Mango")) { InvTPOfield ().Options [i].Click (); break; } } – Taskeen Dec 9 '16 at 5:31
0

Radhika,

For point 3, refer below:

IWebElement fruits =browser.FindElement (By.XPath (".//*[@id='ddlFruits']"));

    fruits.Click();

    for (int i = 0; i < fruits.Options.Count; i++) {

        string fruitTobeSelected= fruits.Options [i].GetAttribute ("text");

        if (fruitTobeSelected.Contains ("Mango")) {

            fruits.Options [i].Click ();

            break;  

        }
    }

The above example is written in C#, you can try the same logic in java:

In above example, we are looping through the options using its index and

checking if the text under a particular contains the value which we want to

select, and if the option contains that value, we are selecting that option. In example we want to select fruit Mango from Fruits dropdown.

0

You can try to mimic the keystroke of pressing the TAB key on the keyboard which will move the focus of the cursor to the next index. after your code just add sendKeys(keys.TAB)

Select Speciality_dd = new Select(driver.findElement(By.name("boardCertificationSpeciality0")));
Speciality_dd.selectByVisibleText("Addiction Medicine");

driver.findElement(By.name("boardCertificationSpeciality0")).sendKeys(keys.TAB);
0

This is because Selenium/Webdriver does not simulate "real" Windows mouse clicks (as it works on the DOM instead), and so it happens sometimes that a "WebDriver click" does not trigger the same Javascript that a manual mouse click does. The solution is to either change the Javascript code itself, or use a software simulates real mouse clicks, for example Kamtu Web Automation or Sikuli.

SikuliX automates anything you see on the screen of your desktop computer running Windows, Mac or some Linux/Unix. It uses image recognition powered by OpenCV to identify and control GUI components. This is handy in cases when there is no easy access to a GUI's internals or the source code of the application or web page you want to act on.

0
String color = "";      
    WebElement Unit= driver.findElements(By.xpath("//p[@class='colorsection']//span[@id='colorselection']")).get(6);
    String styleAttribute = Unit.getAttribute("style");
    System.out.println(styleAttribute);
    String [] values = styleAttribute.split(":");
    color = values[1];
    return color;

Try to get all the Available colors into that Array and select the color you want

  • How does this answer the OP's question? Please edit your answer to explain. – Kate Paulk Sep 27 '18 at 17:45
  • Try to get all the Available colors into that Array and select the color you want – John snow Sep 28 '18 at 7:13
  • When the OP's problem is that the selection they coded isn't causing the side effects they want, this solution will not help them. – Kate Paulk Sep 28 '18 at 11:27

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.