Questions tagged [xpath]

XPath (XML Path Language) is language for addressing parts of an XML document, designed to be used by both XSLT and XPointer. It also provides basic facilities for manipulation of strings, numbers and booleans. XPath uses a compact, non-XML syntax. XPath operates on the abstract, logical structure of an XML document, rather than its surface syntax.

Filter by
Sorted by
Tagged with
35 votes
6 answers
341k views

A way to match on text using CSS locators

So I use xpath locators and slowly converting to CSS. I haven't found a way to do an exact match based on text. For example converting //a[text()='Log Out']. I know you can do css=a:contains('Log ...
Brian O'Neill's user avatar
26 votes
6 answers
119k views

How to handle dynamic changing ID's In XPath?

How to Handle Dynamic Changing IDs In XPath? for example : //div[@id='post-body-3647323225296998740']/div[1]/form[1]/input[1] In this xpath id "3647323225296998740" is changing every time when ...
Bharat Mane's user avatar
  • 6,785
18 votes
2 answers
70k views

WebDriver: find elements by text

I know that WebDriver can locate links through their text, using find_element_by_link_text or find_element_by_partial_link_text. Is it possible to locate any element (such as li, div, span, ...) by ...
Randomblue's user avatar
15 votes
9 answers
57k views

How to write XPath if I have 'apostrophe' in my XPath element?

I came up in a situation where I have to identify an element using XPath and my element starts with apostrophe ('). I will give the example below. This is the usual way we write some XPath. By ...
sarath's user avatar
  • 409
14 votes
6 answers
25k views

Which locator do you use with Selenium: CSS or XPath?

I have heard that, when using Selenium, the CSS Locator has better performance than the XPath Locator. Which Locator do you use in your tests? Have you seen a great performance improvement when ...
Tarun's user avatar
  • 3,437
12 votes
3 answers
3k views

Is jQuery faster than CSS/Xpath selectors for IE 8.0 in Selenium1?

I am planning to run my existing Selenium 1.x tests in IE 8.0. After checking few blogs and reading this, I tried to run my tests using jQuery locators with the method mentioned here. My tests uses ...
A.J's user avatar
  • 793
11 votes
4 answers
97k views

Webdriver: How to find the element using text() in xpath?

I'm new to selenium and HTML. I want to perform click operation for the elements "Users" and "Admins" as one after another. Below mentioned is the HTML code, unfortunately I can't modify it. <ul ...
jass's user avatar
  • 333
10 votes
6 answers
38k views

Selenium.click not working on some anchor elements

The application that am working on was recently revamped and as part of that a new JQuery calendar was introduced. I need to click on a link in the calendar to select the time and date. However, ...
A.J's user avatar
  • 793
8 votes
3 answers
66k views

"Element is no longer attached to the DOM” StaleElementReferenceException when selecting HTML table row

I am using Selenium 2/WebDriver for automation. I have a table and am trying to select a row in it. When the test runs, I can see the row become highlighted as if it is clicked, but then immediately I ...
squeemish's user avatar
  • 1,265
8 votes
2 answers
94k views

Selenium web driver - how to select child elements

What xpath can I use if the tag name in the code starts with li or span and they are child or parent. The trip id and the name locator didn't execute.
Emir Abdurimanov's user avatar
7 votes
4 answers
4k views

same xpath on the page with dynamic ID selenium java

I have a problem with the two same XPath with dynamic ID on the same page. I have tested for selenium in java, when I need to confirm button on delete upload file. Instead of this, test first submits ...
Hana Puklická's user avatar
6 votes
4 answers
15k views

How should I find the XPath using selenium webdriver and protractor

I'm a beginner in automation testing. I'm trying to select a value from data list and I got an XPath like mentioned below: XPath : html/body/div[2]/div[1]/div/div[1] This is the HTML for the same :...
ShadowTK's user avatar
  • 587
6 votes
5 answers
75k views

Locating element by link text (anchor tag innerHTML) or xpath fails in Selenium 2.0 Webdriver

I'm using Selenium 2.0 web driver. My script keeps failing whenever I try locating something in my page. It throws an exception whether I locate the element by LinkText or by XPath. driver....
JustBeingHelpful's user avatar
6 votes
5 answers
23k views

how to find element by xpath for android appium

Since these nodes don't have ids and text, I have used xpath to find the element but find element fails I have tried different xpaths as below but none work. xpath=//android.view.View[10] xpath=//...
Brian Pai's user avatar
5 votes
3 answers
117 views

Which Xpath is more suitable?

xpath 1 : //div[@class='abc'][.="xyz"]/parent::*/div[2]/div xpath 2 : //div[@class='abc'][.="xyz"]//following-sibling::div/div Above two xpaths are pointing same element. Which is better and why, ...
Gaurav's user avatar
  • 327
5 votes
4 answers
59k views

How to find the first occurrence of a field that exists in multiple places

I have code that includes the following label <label _ngcontent-c18="" translate="" for="517390_radio-button">Missing Applicant's Signature</label> However the label and the code for it ...
RRR's user avatar
  • 111
5 votes
4 answers
4k views

How to generate good locators for elements in Web pages?

This site contains many questions that are about finding the right locator expression (XPath, CSS, etc) for an object in WebPage or about troubleshooting problems related in invalid or dynamic ...
dzieciou's user avatar
  • 10.5k
5 votes
6 answers
25k views

How to locate an element which is inside the iframe?

I'm new to automation testing (I'm using TestNG framework and Java language) I'm having trouble in locating an element which is inside iframe. WebElement iframeSwitch= driver.findElement(By.id("...
Gooner4Life's user avatar
4 votes
3 answers
112k views

How to find element by class name or xPath?

I have problems with finding this element: I tried these finders: IWebElement profilUploadPhoto = driverGC.FindElement(By.XPath("//button[contains(.,'submit')]")); IWebElement profilUploadPhoto = ...
xBamboochax's user avatar
4 votes
3 answers
22k views

XPATH : text()='BUY NOW' is working but not contains(text(),'BUY NOW')

In Flipkart page, I searched for Apple ipads and clicked on first search result. Here, I wanted to click on 'BUY NOW'. Typical page looks like this: I used the following xpath and it worked: //...
Abdul Rahman's user avatar
4 votes
1 answer
18k views

How to indicate an `&nbsp;` in xpath?

Say we have the following HTML code. What I want is to locate to the label element whose text is 'AgendaShowCapacity (1 remaining)' with XPath. <div id="pageContent"> <fieldset> &...
Bruce Sun's user avatar
  • 203
4 votes
2 answers
6k views

Cannot get attribute value when using xpath

I met a problem when I try to get an attribute of one tag. Here is the html code: <rect x="66.5" y="43.5" width="26" height="13" fill="#86E067" stroke="#ffffff" stroke-width="1" class="...
Lehtia's user avatar
  • 149
4 votes
4 answers
17k views

Find first IMG element using XPATH

I am trying to find first fridge IMG element in a e-Commerce page but I could not find it alone, It's identifying all Images under First DIV.. Please share you thoughts I tried below XPATH, is there ...
SQA_LEARN's user avatar
  • 435
4 votes
4 answers
13k views

How to click a link when more than 1 exists?

I want to click the link in one container but the container contains two links having the same identifier. For example: <div id="container" style="height:88 px; width: 310px;"> <a class="...
jeni100's user avatar
  • 41
4 votes
2 answers
2k views

Need help to frame locator for webdriver script

I have a button reach_analysis_button with id="x-auto-7". But directly using that i am not able to locate the element from webdriver. I tried ("//div(@class=’x-window-bwrap’)/div[@class=’x-...
Rakesh Prabhakaran's user avatar
4 votes
3 answers
27k views

Selenium: How to click a button using the button label?

In the HTML code like this: <a class="test-class"> <div class="test-content"> <div class="test-time" data-start="12:13pm" data-full="12:13 PM - 12:50 PM"> &...
Lehtia's user avatar
  • 149
4 votes
2 answers
40k views

how to handle if xpath is same for multiple drop down

I have a situation where i had to handle drop down and click the drop down to select some values. There are two drop down in same page and both has same xpath. The Xpath is giving below. //div[@name=...
sarath's user avatar
  • 409
4 votes
2 answers
611 views

Localization of Ranorex XPaths

Our application is available in German and English, other languages may follow. Given I have an XPath like /form/button[@text="Login"], is there a convenient way to have it translated? At the moment ...
Thomas Weller's user avatar
4 votes
1 answer
26k views

Using xpath to confirm <h4> text with a <strong tag> in the middle

I'm using the Java Selenium WebDriver implementation. I'm searching for a string literal in an tag which has a tag in the middle, i.e. <h4>Some regular text <strong>followed by strong ...
douglas's user avatar
  • 75
4 votes
3 answers
8k views

How can I select <ul> element when class is not active

How can I select "Fiyata göre Artan"? <div class="search-top hidden-xs"> <div class="destination-info hidden-xs"> <div class="search-sort dropdown open"><div class="pseudo-border-...
ubunturk's user avatar
4 votes
2 answers
2k views

Dynamic XPath in Selenium - which input field keeps changing

I tried to find the XPath of a text field username and password, but it keeps on changing dynamically. I won't be able to use starts-with or contains in a findelement using XPath. Here's the HTML DOM- ...
bot13's user avatar
  • 145
4 votes
1 answer
569 views

Find anchor (has other html elements) with specific text

I am trying to find the list item based on the contents in the anchor. I tried using the following xpath //li/a[contains(., 'India')] It is working for unique items, But here, it is matching more ...
Jomin's user avatar
  • 41
4 votes
3 answers
759 views

Can we programmatically update locators on UI Change in UI test automation?

I have been working in test automation for the last 10 years. The problem that keeps coming up and surprisingly is still unresolved is: Can we programmatically update locators on UI Change in UI test ...
Vishal Aggarwal's user avatar
4 votes
1 answer
232 views

How to pull content of a div into a String

I am looking for a way to pull the html or text content of a so I could work with it for a method which validates links amongst text of messages displays on a webpage. I am using selenium and java. ...
MikeG's user avatar
  • 85
4 votes
6 answers
43k views

How to locate an element which is visible only by mouse hover in selenium webdriver

I want to find an element which is visible by mouse hover and I need to click on it and it then opens a text field. When I give the XPath for the element in fire-path, it detects 6 instances of the ...
Gooner4Life's user avatar
4 votes
3 answers
2k views

How to use Jmeter Xpath extractor for multiple run in dynamic API elements

XPath extractor response assertion passed first run but in second run it is getting failed because <name>pc</name> is not coming in API. How to skip this element if it is not coming in ...
lak's user avatar
  • 567
4 votes
1 answer
620 views

Watir can't locate an element with xpath [closed]

I got this html (It's simplified to see the deep) <html> <frameset> <frame> #document <html> <body> ...
user25268's user avatar
3 votes
4 answers
11k views

What do I need to do if dropdown takes more time to populate 1st element from dropdown list?

What do I need to do if drop down take time to populate 1st element from drop down list? Select Cdropdown = new Select(driver.findElement(By.xpath("//select[@id='ClientId']"))); Cdropdown....
Mahesh's user avatar
  • 143
3 votes
2 answers
65k views

How to find a button using both xpath and button text?

I have three buttons withing a div. All three buttons belong to same class (class names are same). What I want to do is capture each button using its text (Buttons have different texts) and xpath of ...
Syrus's user avatar
  • 1,197
3 votes
4 answers
1k views

Xpath for sign out button

I am trying to find out XPath for this "Sign Out" button, can anyone help me?
sree's user avatar
  • 31
3 votes
4 answers
151 views

How different the execution would be if we use ID or xpath with ID?

Since we say that IDs are faster and are preferred over XPaths, how different would the execution of the following be? driver.findElement(By.xpath("//button[@id='Save']")).click(); driver.findElement(...
kanayikkaran's user avatar
3 votes
1 answer
4k views

locating element with one class out of multiple classes inside a div using xpath in selenium

I have below two input fields and I have to find there location I can't use class selector cause iI have to identify element based on formcontrolname and ng-invalid class <div> <input ...
anmol agha's user avatar
3 votes
4 answers
2k views

Unable to locate element as ID changes after refreshing the in Ebay login page

Using JUnit I'm attempting to automate the eBay login. I cannot select the email/username field because field changes id on refresh. Any ideas? input size="40" maxlength="64" name="962970435" id="...
mdriver's user avatar
  • 35
3 votes
2 answers
4k views

What is the hierarchy to use for finding elements - ID, class, name, xpath?

What is the hierarchy to use 'find element' by ID, class, or xpath and so on. Which is preferred over which? For some elements class is being used - is that recommended?
Rajan's user avatar
  • 33
3 votes
3 answers
5k views

Correct CSS selector for selenium

Which css selector's correct for the following HTML code ? <li class="active editing" data-index="0"> <div class="view"> <input class="edit"/> </li> I'm trying to get ...
user3568567's user avatar
3 votes
1 answer
5k views

Unable to click button Selenium Webdriver 3

I have a button I want to click, Selenium isn't giving me an error just stops. I've tried both xpath and css and it just stops. <a ng-click="login();" ng-disabled="loginForm.$invalid || ...
Christian's user avatar
  • 375
3 votes
2 answers
392 views

How to locate XPath for given tag? [closed]

I am trying to automate one of site and the below are the HTML code for same: <a href="http://register.rediff.com/register/register.php?FormName=user_details">Create a Rediffmail account</a&...
Mahesh's user avatar
  • 143
3 votes
2 answers
12k views

Selenium webdriver - Cannot find button inside modal

I cannot click on this button contained in a modal this is the html <div class="col-md-6 col-sm-6 col-xs-12"> <button class="btn modal-button full-btn" id="saveexit" type="button"> ...
eeadev's user avatar
  • 131
3 votes
4 answers
75k views

How to get value of text wrapped in paragraph element <p> with Selenium in Java

I have a button, clicking on it generates a number which is wrapped in paragraph text such as <p>random number <p> , I want to get that random number value and do operations based on ...
Prasad_Joshi's user avatar
3 votes
4 answers
2k views

Xpath captured using Selenium IDE is not running in Selenium RC for Links designed in XML

The below xpath which is captured for links in selenium IDE is not running in Selenium RC. The links are designed in XML. selenium.ClickAt("xpath=/html/body/div/div[2]/ul/li[3]", ""); selenium....
Sakthivel's user avatar

1
2 3 4 5
7