How to get Xpath of sub menu? - selenium

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.

Related

What is the xpath for this upload button?

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.

Robotframework checkbox is not clickable

i really try difference staff to try that this script works but no way, i used name, id, selector, xpath didnt work, i use click element, checkbox should be selected, select checkbox, click button, really i do not understand what i am doing wrong.
this is the website code for the check box enter image description here
this is my robotframework script:
click element css=#nutzungsbedingungen
and this is the error that appears on my terminal:
ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (354, 445). Other ele
ment would receive the click: ...
Thanks for your help
That is because the driver is not focusing in the page - for some reason it gets off the page. When it happens to me, I usually click to focus on the nearest element that I want to check.
The other reason could be that there is an iframe, so first you should be get into the iframe and then could check the box.

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.

Checking if an element(whos xpath location changes) is present using selenium IDE

I am new to selenium. Is there anyway i could test if an element, for example an edit buttons is present in a page. There are multiple edit button and they all have different Xpath positions. Will it work if i use verifytext and give the value as "Edit"?

Element not visible as both the menu and submenu hidden

I want to open cric info and then click on 'live score'menu when the submenu opens, click on 'Desktop scoreboard'.
But the problem is live score menu is under a div which is hidden.
ie and this div is under td
"You can check the structure of the page to get detailed info"
so when i try to click the menu element using driver.findElementBy("xpath") i got the element not visible exception.
So i directly used the javascript used by the developer mopen('m2') which does the job of opening the menu but after this when i execute the command to find the submenu element again get the same error"Element not visible exception".
Tried making div visible by executing jscript.
PFB the code i used:
FirefoxDriver d1=new FirefoxDriver();
d1.get("http://www.cricinfo.com");
((JavascriptExecutor) d1).executeScript("mopen('m2')");
((JavascriptExecutor) d1).executeScript("document.getElementById('m2').style.visibility='visible';");
((JavascriptExecutor) d1).executeScript("document.getElementById('m2').style.display='block';");
d1.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
d1.findElementByXPath("//*[#id='mgDdRht']/tbody/tr[3]/td/a").click();
Also tried using the Actions class but everything in vain ,help is really appreciated
Thanks in advance.
You should be able to do this with an Action chain:
Actions builder = new Actions(d1);
Action clickSubMenu = builder.moveToElement(d1.findElement(By.cssSelector(".Nav td:nth-child(2).navLinks")))
.moveToElement(d1.findElement(By.cssSelector("#m0 td:nth-child(1)#mgDd>table:nth-child(1)>tbody:nth-child(1) td:nth-child(2).PopupTabs")))
.click(d1.findElement(By.xpath("//*[#id='mgDdRht']/tbody/tr[3]/td/a"))).build();
clickSubMenu.perform();
I tested this in c#, and it worked for me. I translated it to Java, but I may have made a syntactical error. Apologies if I have.
What I found is that I needed to move to Series. Then I had to move to Series - the dropdown version, as the dropdown version of Series is a different element than the non-dropdown version. Then I was able to move to the West Indies link, and click it.