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
26 votes
6 answers
121k 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,775
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
0 votes
5 answers
11k views

How do I get particular textNode value of a DOM with Selenium

Hello I am trying to find Load # detail from this site. Also You can refer screenshot too. I have tried with xpath: //div[@class='equipment_item']//text()[preceding-sibling::strong[text()='Load #:']][...
manish kumar's user avatar
35 votes
6 answers
353k 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
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
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
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
2 votes
3 answers
5k views

(C#) Selenium: How to extract information from html and write to a variable

I want to know how to get the HTML tag information and write to a C# project variable. Remember that I can not change the HTML because I do not have access. In the example below, it is necessary to ...
Ronison Matos's user avatar
0 votes
1 answer
4k views

Finding a xpath for text which is followed by break tag

I have below HTML code, in that I have to come up with XPath for the 2nd line of text: "Policy Count - 0". <h2 id ="lblpremiumVol"> "Premium Volume - $" <br> &...
user45674's user avatar
0 votes
3 answers
175 views

facing difficulty to create dynamic xpath for City field of UTest website

I am beginner in automation field, I am trying to automated one of the module, I have tried many different XPATH to fetch proper XPATH for City field o UTest site. Im trying to automate registration ...
shaikhsaliha's user avatar
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
24k 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
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
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
41k 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
2 votes
0 answers
524 views

decompose an HTML list with page fragments

note: Looking for simplest possible example of PageFactory and fragments. I've been referencing an article which uses additional libraries I wasn't aware of. The desired structure: Where there's ...
Thufir's user avatar
  • 367
2 votes
7 answers
9k 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'...
lak's user avatar
  • 567
2 votes
4 answers
18k 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 ...
Som Ghosh's user avatar
  • 197
1 vote
1 answer
36k views

How to use a regular expression to identify xpath of element with autogenerating id

I need to access this element: <input id ="combo-1105-inputWrap"> The 4 digits in the xpath are autogenerated per browser session. I need to find that particular xpath and key in the data. ...
chandrasekhar gandrakota's user avatar
1 vote
5 answers
15k views

XPath to select label plus hidden radio button option using WebDriver

I am unable to write the correct XPath to select the title "MRS" for below code. I am using below code, but unable to execute it. driver.findElement(By.xpath("//div[@value='MRS']")).click(); Getting ...
Arjun's user avatar
  • 43
1 vote
2 answers
4k views

NullPointerException when using @FindBy

I'm getting a NullPointerException when trying to use @FindBy because the object reference is only declared and not instantiated. What is the usage? The docs give example declaration but no instance ...
Thufir's user avatar
  • 367
1 vote
3 answers
3k views

Selenium IDE type not saving text

I am trying to create an automation tool to test a salesforce platform. When I try to create a new form, the text is displayed but it's really just an injection from Javascript. Is there any way to ...
Imran Chowdhry's user avatar
0 votes
1 answer
79 views

How to find an unnamed button belonging to a certain h2 entry XPath

(I am a bit of a StackOverflow newbie, so please forgive any beginner mistakes and let me know what to improve in the future) I am trying to select the highlighted button in the appended picture. ...
Adrian Leonhard's user avatar
0 votes
1 answer
885 views

xpath query for specific String value

My project is crashing with: Element info: {Using=xpath, value=//a[contains(text(), 'Books')]/@href}. The output (crash): thufir@dur:~/NetBeansProjects/com.toscrape.books.selenium$ thufir@dur:~/...
Thufir's user avatar
  • 367
0 votes
2 answers
1k views

How to get unique xpath with dynamic @id? [duplicate]

Hi I am facing problem to identify cause @id is dynamic :- //div[@id='SubmissionWizard:LOBWizardStepGroup:LineWizardStepSet:WC7LineCoverageScreen:WC7LineCoverageCV:WC7ConditionsDV:5:CoverageInputSet:...
sidharth's user avatar