How to traverse all the element of dropdown in Selenium WebDriver? - selenium

I have a drop down on my web page and I have to traverse this drop down and select the specific one.But its not so simple, In this the traversing should be show by the hover and at last the specific element or item should be selected.(The mouse hover action should start from the first element till the required element and then select the element).

You need to look into Select, there are a couple of different ways of selecting elements from the dropdown, below is one example.
Select dropdown = new Select(<WebElement>);
dropdown.selectByVisibleText("text");

Related

Print all hidden locator of drop down element values and select one by one of react bootstrap

We have react bootstrap app which has Dropdown field, trying to get Xpath and select drop down value however when selected drop down value html doesn't show locator or it has hidden element locator as shown in the picture.
Here in the picture, <input tag.. has aria-activedescendant="ch...demo-option-**0**"> for the first drop down value, if selected second drop down manually then it will change to < "ch...demo-option-**1**">
But this locator kind of hidden, unless mouse over on the drop down element this demo-option-0 doesn't show.
How to find this drop down element and get all values to print, select all check boxes.

How to get XPath of an element when it is in sub tab (Salesforce Lightning component)

In the following snippets, XPath for the drop down element in last column of accounts table is similar in Subtab and Main page.
I am using the XPath expression
//table/tbody/tr[2]/td[10]/span/div/a[2][#role="button"]
to click on drop down element. But unable to do so as it happens to appear in the previous page too.
Please help me in identifying unique irrespective of tabs.
You can use this XPATH :- (//table/tbody/tr[2]/td[10]/span/div/a[2][#role="button"])[1]

How to select absolute link if two links are having same text in them?

I am having two link
Engagement Rings
Rings
The above links are check box under dropdown menu
how can i select Rings using selenium xpath using text() method
Below is what i tried, but it is selecting "Engagement Ring"
//li//a[contains(text(),'Rings')]
but it is selecting Engament Ring as it appears before Rings in menu
My Code:
//Select Sub-Menu item from collection dropdown
WebElement selectSub = driver.findElement(By.xpath("//div[#class='popover fade right in']//div[2]//li//a[contains(text(),'Rings')]"));
This is selecting Engagement Rings because you are using contains() method
it will locate the element which contains match text So your first checkbox has "Rings" text
Just change your xpath to :
//li//a[text()='Rings']
OR
//li//a[normalize-space()='Rings']
Please try below xpath i hope it will work
//li//a[starts-with(text(),'Rings')]

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

Having issue in selecting drop down element under makemytrip website

Having issue in selecting drop down element under the following website
http://flights.makemytrip.com/makemytrip/fareCal.do?intid=NewHP_to_DF_FC_Menu
I'm unable to select any one of the cities listed below.
Please help me out resolving the same.
Scenarios Tried
driver.findElement(By.className("chzn-single")).click();
driver.findElement(By.xpath("//span[contains,'NewDelhi']")).click();
driver.findElement(By.xpath("//span[#id='fromcity_chzn']")).click();
This works:
WebElement leavingFrom = driver.findElement(By.xpath("//*[#id='fromcity_chzn']/a"));
WebElement goingTo = driver.findElement(By.xpath("//*[#id='tocity_chzn']/a"));
leavingFrom.click();
leavingFrom.sendKeys("Bangalore");
leavingFrom.sendKeys(Keys.RETURN);
goingTo.click();
goingTo.sendKeys("Goa");
goingTo.sendKeys(Keys.RETURN);
Here is working sample:
//First get main dropDowns
var leavingFromDropDown = driver.FindElement(By.Css("#fromcity_chzn"));
var goingToDropDown = driver.FindElement(By.Css("#tocity_chzn"));
//Select value from first dropDown using dropDown items index
//First click on dropDown to open it
leavingFromDropDown.click();
//Now find items in it and click on any item using it's index (also can be used method to access this elements using their names
leavingFromDropDown.FindElements(By.Css(".active-result"))[1].click();
//this dropDown closes automatically, but if not you need to click on it again to close
//Same perform with second element
goingToDropDown.click();
goingToDropDown.FindElements(By.Css(".active-result"))[2].click();
If you want to use input box to enter any value from DropDown you need to find that element and using sendKeys set it's value. E.g.:
leavingFromDropDown.click();
var input = leavingFromDropDown.FindElement(By.Css(".chzn-search > input"));
input.sendKeys('Goa');
input.sendKeys(Keys.Enter);//or tab