XPath for "Onclick" attribute - xpath

I have to perform a click event on one of the option in a drop down menu on a web page, here is my absolute path for the element.
Absolute Path:-
And I have tried Xpath to find the element:-
All the combination of Xpaths that I tried are not working.
Please do suggest me if you have any solution for the same?
Many Thanks,
Shruti

Try with these Xpaths:
//a[#data-original-title='Excel']
//a[#alt='Excel']
//a[text()='Excel']

Related

Setting the correct xpath

I'm trying to set the right xpath for using RSelenium, but I'm not very experienced in this area, so any help would be much appreciated.
Since I'm not allowed to post pictures yet I have tried to add a link to a screenshot of the html:
The html
I need R to scrape the dates (28-10-2020 - 13-11-2020), but so far I have not been able to set the correct xpath when using html.nodes.
I'm trying to scrape from sites like this one: https://www.boligsiden.dk/adresse/topperne-9-3-33-2620-albertslund-01650532___9__3__33
I usually do this on python rather than R
As you can see in this image when you right-click on the element concerned. You get a drop-down menu with an x-path to the element.
Other than that, the site orientation and x-path might change and a full x-path might be a good option in the short-run, so I rather prefer driver.find_element_by_xpath('//button[contains(text(),"Login")]')\ .click()
In your case which would be find_element_by_xpath('//*[contains(#class, 'u-pb-4 u-block')]')
I hope this helps and it is mostly the same across different languages

How to click element on pseudo element ::after in Robot Framework

I would like to Click button at ::after but I don't know how to create xpath from pseudo element
I try this way //em[#class='x-btn-split']::after but it's not work.
Please anyone help.
You can use directly id='ext-gen33'. But if you want xpath only then include 2 attribute if there are many matching buttons
xpath = //button[#type='button' and #id='ext-gen33'].

Robotframework xpath how to locate element

I want to click on this element:
<a id="welcome" class="panelTrigger" href="#">Welcome Admin</a>
but I am not able to locate this element.
I have tried:
id=welcome, xpath=//*[#id="welcome"]
Click Element or Click Link but it is not working. Can you please help me?
I think you should be fine any of the lines below:
Click Link id:welcome
Click Link Welcome Admin
Based on the documentation:
When using the default locator strategy, links are searched using
id, name, href and the link text.
So if the ID does not happens to be unique you can still refer to the link by its text.
Try this way
Scroll To Element xpath ${element_locator}
Wait Until Element Is Visible ${element_locator} timeout=30s
Click Element ${element_locator}

How to locate an element having href='#' attribute in anchor tag

abc
I am not able to locate above element. I tried //*[#id="contact-groups"], but with no success.
Well, XPath is not the best of the methods to find elements. But following will match the links with href = "#".
//a[#href="#"]
Not sure if your scenario is as simple as your question. I did test this with a simple html page.
The locator seems correct. You could try this too:
.//*[#id='contact-groups']
As per HTML code provided you can try below xpaths
//a[#id='contact-groups']
//a[contains(text(),'abc')]
//a[#href='#']
Thanks
I am guessing the link is in an Iframe.
Use the following code to switch to the frame and then click on the link
driver.switchTo().frame("frame-name");
driver.findElement(By.xpath("//a[#id='contact-groups']")).click();

Xpath for Log-in

I am trying to click on "Log in" link present on home page of "stackoverflow" using xpath as show as below. But no success
driver.findElement(By.xpath("//a[contains(text(),'log in')]")).click();
Please help what i m missing here.
Thanks
Use the following xpath:
//a[#class='login-link'][text()='log in']
I tried personally and it worked with me. Hope it helps.
The xpath which you have used in your question returns two webelements:
​log in​​
​log in​​
that's why selenium is not able to click on that.So use
//a[#class='login-link'][text()='log in']
Try this :
driver.findElement(By.xpath("//a[#class='login-link' and .='log in']").click();
Above XPath match <a> tag having class attribute equals "login-link" and inner text equals "log in".
General tip: always prefer . over text(). There are very rare situations when you have to filter element specifically by using text().

Resources