Hi
I am not able to find the correct xpath for the Html code added in the attachment.
I have written below xpath but it is not working.
//div[#class="calendar-item-title"][1]//*[#class="calendar-item-time"][1]
Please find attached image for more details of Html code.
div[#class="calendar-item-title"] does not have a child *[#class="calendar-item-time"] according to your image.
Your *[#class="calendar-item-time"] is in div[#class="items-container"]
so your xpath would be:
//div[#class="items-container"][1]//a[#class="calendar-item-time"][1]
Just add : "/parent::*" at the end of //div[#class="calendar-item-title"] if you want the parent element
Try this xpath :
//a[contains(text(),'12:30 am')]
try with the below xpath
driver.findElement(By.xpath("//a[text()='12:30 am']")).click()
from ur image, its not clear there are more 12.30 containing text or not. In that case, use
driver.findElements(By.xpath("//a[text()='12:30 am']")).get(0).click();
Related
I want to create a xpath for UNLIMITED DATA with the help of //android.widget.TextView[#text='Active'] xapth.
I have tried to locate the element using the below XPath using following-sibling and child but it didn’t work.
//android.widget.TextView[#text='Active']/following-sibling::androidx.recyclerview.widget.RecyclerView/child::androidx.cardview.widget.CardView/child::android.widget.TextView[contains(#text,'UNLIMITED Data')]
Please find the below image for your reference.
enter image description here
enter image description here
Please help.
Can you try this XPath :
//android.widget.TextView[#text='Active']/following-sibling::androidx.recyclerview.widget.RecyclerView[1]//android.widget.TextView[contains(#text,'UNLIMITED Data')]
<div class="bInputTab">
<ul>
<li class="onNow">网银支付</li>
<li>账号支付</li>
</ul>
</div>
How can I get the element in the red box using By?
Many thanks!
Try following xpath,
//a[#onClick='On click Value']
You could use xpath, tagName, all depends on HTML structure, You can find parent element, and search downwards:
//li[#class='onNow']/following-sibling::li[1]/a
if its only link in DOM driver.findElement(By.tagName("a"));
Hope this helps,
This XPath should work :
//li[#class='onNow']/following-sibling::li[1]/a
The link text should also work as well
driver.FindElement(By.LinkText("账号支付"));
Actually I did not show the key structure of the HTML. It is because the element is not in the default frame. So I add the WDS.browser.switchTo().frame("frame_main") to the code, it works.
Thanks for all of your help.
The reference is The WebDriver Sampler: Your Top 10 Questions Answered
The element’s locator is invalid
2. The element belongs to another frame
The element is not available in DOM yet
I need to get the value 107801307 that is inside a specific Div but there are several other Divs in the path before getting into that DIV I need. Can anyone help?
Below is the image with the information that I need to extract from the DIV.
As per the HTML you have provided, to extract the text 107801307 you can use the following solution:
Java:
String myText = driver.findElement(By.xpath("//b[#class='label_tratamento'][contains(.,'Ban Claro')]//following::span[1]").getAttribute("innerHTML");
Python:
myText = driver.find_element_by_xpath("//b[#class='label_tratamento'][contains(.,'Ban Claro')]//following::span[1]").get_attribute("innerHTML")
Research xpath locators to find the specific element you want.
Assuming you were using Java, the code would be:
webdriver.findElement(By.xpath("//b[text()='Ban Claro']/following::span").getText();
or
webdriver.findElement(By.xpath("//b[#class='label_tratamento']/following::span").getText();
Use:
driver.findElement(By.xpath(("XPATH OF DIV HERE")[Index of the div where span is. Example: 4)/span)).getText();
I am trying to locate element using relative XPath. I have attached HTML schema of the element. Below is the XPath I am using:
//a[contains(text(),"Sales")].
If you want to locate link by text you might need to use search by link text instead of XPath:
Java:
driver.findElement(By.linkText("Sales")).click();
Python:
driver.find_element_by_link_text("Sales").click()
Note that you should use exact value as it appears on rendered page in browser:
if it appears as SALES:
driver.find_element_by_link_text("SALES")
if it appears as "Sales":
driver.find_element_by_link_text("\"Sales\"")
In case some extra text is added by ::before pseudo-element, you can also use search by partial link text:
driver.find_element_by_partial_link_text("Sales")
//*[#class='**your class name**']//*[text()='Sales']
Hope above XPath helps you!
I tried to locate use element with attribute value '#aaa' for below snippet
<svg>
<use xlink:href='#aaa'></use>
</svg>
I was able to locate using css selector use[* |href='#aaa'] . But I require it in xpath. I tried below xpath but it is not working
(//*[name()='use'])[ * ='#aaa' or #href='#aaa']
Note :I need to use the value '#aaa' to differentiate from other elements.
Could anyone please help to construct this xpath.
Your predicate [ * ='#aaa' or #href='#aaa'] returns false as there is no attribute as href (but xlink:href), and use has no child nodes with text content '#aaa'.
Note that wild-card for any attribute is #* while just * is for any node (except attribute). Try below XPath
"//*[name()='use' and #*='#aaa']"
lookout, if someone needs contains..
"//*[name()='use'][contains(#*='#aaa')]"
as none of the suggestions really worked for me, I came up with following (tested in chrome devtools):
//*[name()='use' and #*[contains(.,'#aaa)]]
comments:
name()='use'
because a normal tag search (i.e //use) did not work
#*[contains(.,'#aaa')]
because contains with a wildcard (i.e. contains(#*,'#aaa')) didn't work
Use the xpath
//use[#xlink:href='#aaa']
or
//use[contains(#xlink:href,'#aaa')]
As the element is within svg namespace you can use the following xpath:
//*[name()="svg"]/use[contains(#xlink:href,'#aaa')]
This is an SVG tag and it works a little differently
Please try below xpath:
//[local-name()='svg']/yourxpath
For XPath:
//*[name()='use'][contains(#*, '#aaa')]
Or variant provided by Andersson
Approaches with [#xlink:href='#aaa'] don't work on practice