Robotframework xpath how to locate element - xpath

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}

Related

Need help locating element with XPath

I am learning about xpath , can you help me go to the "i class" tag and click on reddit's up vote icon. I tried to find the comment text
I can connect the paragraph
//div[contains(p/text(),'The user name completes this')]
and find the up vote icon tag right below this comment
https://www.reddit.com/r/me_irl/comments/zg7nr5/comment/izgy4a3/?utm_source=reddit&utm_medium=web2x&context=3
You can locate the parent div block of the entire comment by the text content and then go to upvote button inside it as following:
"//div[contains(.,'The user name completes this')][contains(#class,'Comment')]//button[#aria-label='upvote']"
I'm not sure you really need that i icon element so I gave the locator of the upvote button.
In case you really need the i element inside it - it can be located similarly as following
"//div[contains(.,'The user name completes this')][contains(#class,'Comment')]//i[contains(#class,'upvote')]"
Like this:
//div[contains(.,'The user name completes this')]//button[#data-click-id='upvote']

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'].

XPath Next Page navigation

I'm using Chrome Data Miner, and so far, failing to extract the data from my query: http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free
How to code the Next Element Xpath for this website? I tried all the possible web sources, nothing worked.
Thanks in advance!
You could look for a tags (//a) whose descendant::text() starts with "Next" and then get the href attribute of that a element.
% xpquery -p HTML '//a[starts-with(descendant::text(), "Next")]/#href' 'http://www.allinlondon.co.uk/restaurants.php?type=name&rest=gluten+free'
href="http://www.allinlondon.co.uk/restaurants.php?type=name&tube=0&rest=glutenfree&region=0&cuisine=0&start=30&ordering=&expand="

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().

xpath - how to show the anchor text of a specified link

I would like to search for a link on a page by its domain name - possibly using contains()? And then only show the anchor text of that link.
I've been able to get all of the a tag using
//a[contains(text(), 'domain_name')]
but unable to retrieve just the anchor text. Can anybody help?
Just use the text() node:
//a[contains(#href, 'domain_name')]/text()

Resources