What is the xpath for this upload button? - selenium

This is a dropdown menu. Can someone help to write the relative xpath for this to use as a locator in selenium automation?
I have tried with //a[text='Upload']

You try by right clicking the element in the browser under inspect element to get this (here showing post your answer in stack overflow for example, after the right click) then copying the XPATH, this would give another way of the same xpath, and referring this xpath might be a solution to your problem.

Related

How to find element by xPath in Ghost Inspector

Hi have to click an element using its xPath in Ghost Inspector but its not working for me, the syntax I tried were:
"xpath=".XPATH
"xpath="XPATH
xpath=.XPATH
xpath=XPATH
all the above thing that I tried didn't worked and Ghost Inspector was saying:
"ELEMENT NOT FOUND"
can any one please help me finding element using its xPath in Ghost Inspector
you should use xpath=//
For example: xpath=//*[#id="main-container"]/div[1]/my-header/div
Documentation: https://ghostinspector.com/docs/test-editor/#targets
I am using developer tools in Chrome and there I can choose (by mouse right click) what value I want to copy. Try to copy xPath, it should work, I use them a lot.

How to get Xpath of sub menu?

How to get Xpath of submenu when user click on main menu in selenium?
I have tried with finding ID and attribute name but its not working.
Please help
You can try the Firebug/Firepath add-ons if your using the Firefox browser to get the xpath values generated by the tools. If those don't work then share the HTML code for better clarifications.
Probably your element of submenu is not visible at the current time when you are tried find it by ID or Name. You should to make click on Menu and only then try to find this element of submenu by ID or Name - it have to be visible.
If you will not find element of submenu this way, write here HTML-code of page and your selenium-script.

How can I get the XPath expression from a web site's HTML content?

I want to use XPath expressions in Selenium code, but I don't know how to get it from a site's HTML code.
I'm using the Google Chrome web browser.
The easiest way is to inspect the element you want to get the XPath expression for. Then click on the highlighted code and Copy → Copy XPath which give you a full XPath patch you can copy to your code.
For Firefox, you should install Firebug or another extension like this.
As neliCZka suggests, you could also try to build a relative path if its possible by trying to find the proper XPath in the search bar in Chrome after inspecting the element.
I see that someone has downvoted the suggestions to use the Copy XPath option from different inspection tools. That's probably because these paths can often be difficult to maintain as the application changes, won't work in Selenium because they're not sufficiently unique, or can just be unreasonably complex for complex HTML.
Copy XPath... is useful as a starting point though. If you're not familiar with XPath, this tool can help you to get a better feel for how to apply it to your HTML content, but it's very important to learn how to use XPath yourself.
Right click on the element you want to have an XPath expression for, and then click Inspect Element. A new frame will open with the HTML source code.
Now right-click on the code and select "Copy XPath".
Note: you will have to remove " WITH ' after copying it into your code
Install Firebug for Firefox. ...
Open the website that you want to inspect. ...
Click the Firebug button. ...
Click the element inspector button. ...
Click the web page element that you want to inspect. ...
Right-click the highlighted code in the Firebug panel. ...
Select "Copy XPath" from the menu.
You can press F12 to get the check page, select your hoped HTML code, and hit the mouse 2. It has the copy option, and there is a copy XPath.

How do I retrieve the xpath of a clicked element in Selenium?

Is there a way for me to select an element in a web browser, using Selenium IDE and get an XPath of the item I clicked on (regardless of whether it is text or button?)
TIA
There is no such thing as "the" XPath. Every element has many Xpath, there is no definitive.
Some Xpath are brittle, some are stable, some are reliable, some are unstable.
The "best" and most suitable has to be a human decision. Browsers allow you to test and experiment with Xpath.
You can get "the" xpath - but it would be an absolute path to the element which is usually not reliable and very fragile. In the firebug firefox extension find an element and select "Copy xpath" from the menu.
In Selenium IDE, click the Select button beside the Target text box. And then move your mouse pointer to the web element that you want to check (it will be highlighted). Click on the element. In the IDE, click the Target dropdown box. Select the xpath that you want to use.
Alternatively, if you do not want to use IDE, you can also use the Developer Tool panel in Chrome or Firebug plugin in Firefox to get the xpath.
In Selenium IDE, by keeping the recording mode on, then clicking on the element you want to capture, you can find all the locators of that web element that are captured by the Selenium IDE (if the selenium IDE is able to capture the web element). After recording that element in IDE , click on the drop down in the Target bar (on right end of Target bar), you will find all the locators including xPath (css as well).

Two elements with same parent element

I am using Selenium IDE to test a tree.
I am having two elements with same parent element, one is a check box and the other is a text.
My question is, can I use the text element to make selenium click on the check box?!
in another way, can I connect the two elements to each others some how?!!
As for me I am right click on the browser webpage that I want to test. And I can easily chose by show all available command. Note that when you right click on the browser you need to open your selenium-ide.
Hope this will helpful.