I need help to identify the xpath for entering text and select from a dropdown (in https://www.phptravels.net) using Robot framework.
Click on Hotels option
enter text like 'Delhi
enter text like 'Delhi' and select from dropdown the city 'Delhi
Using Robot framework and selenium library.
Input Text xpath://*[#id=\"select2-drop\"] Delhi,India
Input Text xpath://*[#id=\"select2-drop\"]/div/input Delhi,India
Input Text xpath://*[contains(text(),'Search by Hotel or City Name')] Delhi
I get following error:
Element with locator not found
In the case of xpath: [contains(text(),'your_text')] should work.
Try this:
click element xpath=//*[#id="s2id_location"]/a/span[1]
input text xpath=//*[#id="select2-drop"]/div/input Delhi
wait until page contains element xpath=//li[2]/div/span[contains(text(),'Delhi')]
click element xpath=//li[2]/div/span[contains(text(),'Delhi')]
page should contain element xpath=//a/span[1][contains(text(),'Delhi, India')]
Instead of Click element try Press Keys <locator> //13. That would work.
Related
enter image description here
I have to select a name from this searchbox based on my input value. How I can achieve this.
#send something to the input
input=driver.find_element_by_xpath("//input[#role='combobox']") #xpath to input box
input.send_keys("something")
#find the drop down element and scroll to that element
options = driver.find_element_by_xpath("xpathtotheoptiondropdown")
driver.execute_script("arguments[0].scrollIntoView();", option)
#click that element
option.click()
Option 1:
If html tag for Account name is <select>...</select>, you can use org.openqa.selenium.support.ui.Select
See https://www.guru99.com/select-option-dropdown-selenium-webdriver.html
Option 2:
Use relationship parent-child of elements.
See Selenium Java : Dropdown items are updated dynamically
and https://www.tutorialspoint.com/locating-child-nodes-of-webelements-in-selenium
There are many span tags as mentioned in the image below and each has its own a-tag with unique id as "chooseitem". I need to choose particular a tag using names in the span tags.
Need to click the a-tag button using the text Mayo Chicken from the above HTML snippet in the image.
I have tried the below Selenium script
WebElement select = driver.findElement(By.xpath("//*[contains(text(),'Mayo Chicken (Single)')]"));
WebElement add = select.findElement(By.id("chooseitem"));
It doesn't work for me.
driver.findElement(By.id("chooseitem"));
The above code chooses the first item in the page by default as its id is also 'chooseitem', but need to define what to be chosen.
Can anybody help me out?
We need to get the common parent(ancestor) element of the chicked and the clickable 'a' tag, then we can navigate to the tag 'a'. Below xpath should ideally work.
"//span[contains(text(),'Mayo chicken')]/ancestor::div[4]//a"
Note: Here i have used div[4] because fourth parent is the common ancestor for 'Mayo chicken' and tag 'a'.
For more details about different xpath axis refer this->https://www.w3schools.com/xml/xpath_axes.asp
Hope this helps you. thanks.
You can do that by using the xpath position, press F12 for developer tools click on "Select element button", click the element that interests you on the page, as in your picture you will see one or more lines highlighted, right click the line -> Copy -> Copy xpath. You will have something like the line below:
//*[#id="comment-76500216"]/td[2]/div/span[1]
The xpath position will be:
//td[2]/div/span[1]
You can use that when you have multiple elements that share the name or id or so on.
And you will have:
WebElement select = driver.findElement(By.xpath("//td[2]/div/span[1]"));
PS: I used google chrome
My Selenium web driver is not clicking on this tree node. I don't know exactly what we say it tree node or something else so this is image and I highlighted the element.
This right arrow part on which I want to click
And this is my code:
//wait.until(ExpectedConditions.elementToBeClickable(By.id("iconDiv")));
WebElement taskdropElementid = driver.findElement(By.id("iconDiv"));
System.out.println(taskdropElementid.getAttribute("class"));
if(taskdropElementid.getAttribute("class").equals("RightArrow"))
taskdropElementid.click();
Printing statement is giving me output dropdown. I think it should give RightArrow and when I am uncommenting wait part then it is continuously wait for the element to be clickable.
What am I doing wrong?
Printing statement is giving me output dropdown
That means there are multiple elements with the same id iconDiv and unfortunately you're locating other element instead which has class name dropdown.
If you want to locate element with class name RightArrow, You should try using By.cssSelector() to locate it uniquely as below :-
WebElement taskdropElementid = driver.findElement(By.cssSelector("div#iconDiv.RightArrow"));
taskdropElementid.click();
enter image description here
I created my own xpath using the value as
.//*[#onclick='return clickFileUpload('openssme1')']
But it is not locating the choose file option individually.
Please help me to locate them individually so that i can choose 5 files.
If I want to select a specific element and I know the position in the result generated by the xpath. Then you can simply append [n] to the end of the xpath, where n is the position number.
(//button[text()="Choose File"])[1]
You can select your element with other unique identifier. In your case, you can choose the number at the left of your button (the number)
Something like this :
//*[#id='uploaderList']/tr/td[contains(text(),'1')]/../td/button
I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.
I am using following code sequentially to get the tooltip text of all 5 elements:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
The issue is I get only the tooltip text of first element printed in console.
Is it because I need to refresh or reset the builder?
It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.
Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.
Console.WriteLine(Element1.GetAttribute("title"));
Console.WriteLine(Element2.GetAttribute("title"));
Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.
Console.WriteLine(InputElement1.GetAttribute("title"));
Console.WriteLine(ImageElement1.GetAttribute("alt"));
http://www.javascriptkit.com/howto/toolmsg.shtml
I think, it needs to release from element as:
builder.release(Element1).perform();
So, your code could be as below:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.release(Element1).perform();
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.release(Element2).perform();
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
builder.release(Element3).perform();
I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.