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
28
votes
3answers
164k 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 ...
15
votes
2answers
67k 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 ...
14
votes
5answers
52k 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 ...
14
votes
6answers
23k 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 ...
12
votes
3answers
2k 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 ...
8
votes
4answers
62k 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 ...
8
votes
6answers
20k 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, ...
7
votes
6answers
20k 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 ...
7
votes
4answers
3k 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 ...
6
votes
3answers
42k 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 ...
5
votes
3answers
102 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, ...
5
votes
5answers
60k 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....
4
votes
4answers
10k 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 :...
4
votes
1answer
9k 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> &...
4
votes
4answers
6k 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="...
4
votes
2answers
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-...
4
votes
4answers
6k 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 ...
4
votes
3answers
12k 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"> &...
4
votes
2answers
313 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 ...
4
votes
1answer
14k 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 ...
4
votes
3answers
308 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 ...
4
votes
1answer
180 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. ...
4
votes
6answers
10k 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("...
4
votes
1answer
596 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 ...
4
votes
1answer
418 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> ...
3
votes
3answers
6k 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....
3
votes
3answers
62k 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 = ...
3
votes
4answers
3k 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 ...
3
votes
2answers
4k 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="...
3
votes
2answers
3k 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?
3
votes
1answer
18k 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=...
3
votes
3answers
3k 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-...
3
votes
4answers
44k 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 ...
3
votes
2answers
1k 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- ...
3
votes
4answers
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....
3
votes
1answer
118 views

Differences in methods to select an element based on content in XPath

Selecting an anchor link with content, such as <a>test link</a>, I can see three different ways to do it using XPath: a[text()="test link"] a[.="test link"] a[contains(text(), "test link")...
3
votes
2answers
149 views

How to find the xpath for the link given below?

Please help me find the xpath for the page https://www.seleniumhq.org/download/ In this page there is a para "Selenium Standalone Server". In that I have to find the xpath for Download version link "...
3
votes
1answer
188 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 ...
3
votes
5answers
15k 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 ...
3
votes
2answers
5k views

How to get XPath of a list element generated by AJAX?

When I type a keyword ("Documents 1.xml") driver.findElement(By.id("documentSelect_enter")).sendKeys("Documents 1.xml"); in this field: <input id="documentSelect_enter" type="text" style="width:...
3
votes
2answers
174 views

Identifying if an element is present or not using selenium

I have a SAVE button which is active only if I do some changes and then trying to save it. Otherwise its disabled. This is the html for that button: <button id="customize-site-save" class="...
3
votes
3answers
132 views

Xpath Axis Selection [closed]

The following xpath selects siblings of selected context. But I'm confused about the following xpath expression: xpath://h2[contains(text(),'A few of our most popular courses')]/parent::div//div[//a[...
2
votes
7answers
6k views

How to find the xpath locator for logout button?

We are currently working on a selenium project. Can you guys help me to find the xpath locator for the logout button in the application? Below is a screenshot of the code for the element for which I'...
2
votes
3answers
13k views

How to access a Hyper link using XPath

What is correct format for using XPath? Does XPath vary with the browser? drchrome.findElement(By.xpath("//a[contains(.,'Google')]")).click();
2
votes
5answers
560 views

Xpath: which is much more reliable source - Chrome or Firefox?

On Google chrome, inspecting an Element and copying it's xPath gives me the following value //*[@id='Body']/app-root/app-generic-product/section[2]/div/app-product-summary-list/app-product-summary[2]/...
2
votes
4answers
453 views

Xpath for sign out button

I am trying to find out XPath for this "Sign Out" button, can anyone help me?
2
votes
4answers
14k views

How to work with changing element id in the html code [duplicate]

I am working in a ERP where the elements id are changing/rotating randomly. so if I am writing a code to locate a id, next time I run the selenium code it gets me error as the id changes by that time ...
2
votes
4answers
96 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(...
2
votes
4answers
3k views

Selenium — How to deal with 2 submit buttons and click on one of them?

The key HTML is: <div class="col col3 actionCol"> <button type="submit" class="booking fRight">Book</button> </div> but we also have other forms on the same page, e.g. for ...
2
votes
5answers
12k views

Cannot locate button with changing ID in Selenium

I am working on a project where I have to locate a button. I have used XPath for that, but the button's id changes on every refresh, so I am facing a problem with that. Below is a HTML excerpt. Let me ...