21
votes
How to handle dynamic changing ID's In XPath?
At this situation, We have lots of options-
Option 1: Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then ...
11
votes
How to handle dynamic changing ID's In XPath?
Use contains() or starts-with() function in XPath:
Solution:
With contains():
//div[contains(@id,'post-body')]/div[1]/form[1]/input[1]
With starts-with():
//div[starts-with(@id,'post-body')]/div[...
11
votes
What do I need to do if dropdown takes more time to populate 1st element from dropdown list?
Do you think that time is the problem here?
If so try to increase the time you are providing in Thread.sleep(); and see it that works out for you.
If its not the time, then did you try to find out ...
10
votes
How to write XPath if I have 'apostrophe' in my XPath element?
The character ' is an apostrophe. The colon character is :.
Selenium unfortunately only supports XPath 1.0, so this is tricky. You can do it by escaping the ' with a backslash like this:
By.xpath("//...
9
votes
How to find the xpath locator for logout button?
If you want to do it manually, then you will have to trace the path from the root of the host up to where the element is being generated.
OR
There is an easy way to get the xpath. In Mozilla FireFox ...
8
votes
How to handle dynamic changing ID's In XPath?
Use other elements and attributes for partial and combination matches
Generally in these cases of database backed and changing ID's in web element selectors your options are to look for one or more ...
7
votes
Accepted
How should I find the XPath using selenium webdriver and protractor
Avoid the use of 'Absolute XPath' if possible in your coding.
If your element is having with class, ID, name & Type attributes then try to locate the element with the use of Relative XPath.
You ...
7
votes
How to find the first occurrence of a field that exists in multiple places
In XPath there are a couple of ways you could try this.
Match by text (can be partial text too)
(//label[contains(.,'Missing Applicant')])[1]
Match by tag (if that helps isolate the label from ...
7
votes
Accepted
How to find a button using both xpath and button text?
Use below command for finding the button via text:
driver.findElementsByXPath("//button[contains(text(),'Text in your webpage')]");
This will work to capture all the 3 buttons with the same class ...
7
votes
Accepted
XPATH : text()='BUY NOW' is working but not contains(text(),'BUY NOW')
It is an interesting question.
Let me share my findings. First of all //button[contains(text(),'BUY NOW')] doesn't really look up the element in Chrome dev tools. But //button[contains(.,'BUY NOW')] ...
6
votes
Accepted
What is the hierarchy to use for finding elements - ID, class, name, xpath?
My main criteria is readability and maintainability.
Speed has never been as issue for me. There's other parts of the test frameworks I use that have much more significant speed issues.
The basic ...
6
votes
Accepted
How to find element by class name or xPath?
can you please try the options below:
By Xpath:
button[@type='submit']
button[@class='btn btn-success']
button[@type='submit'][@class='btn btn-success']
By css selector:
button[type='submit']
...
6
votes
Xpath for sign out button
There are much better ways to locate the element aside from using XPath, don't focus on XPath too much - this is, generally speaking, the slowest and the least readable way to locate elements.
I ...
6
votes
How to access a Hyper link using XPath
Whenever you are trying to locate Hyperlink Element & you have '/a' attribute, just forget about the XPath method and try using linkText element Locator.
<html>
<head>
<title&...
6
votes
Same Xpath expression returns different results
Because in your first example all your span elements reside on the same level so that they all have different positions. However in your second example each span resides within its own container (<...
6
votes
Element not found in a runtime
This could be a timing issue(as most of the scenario you already discussed) when you're going to find it would not be present at that time on DOM, so you should try using WebDriverWait to wait until ...
6
votes
locating element with one class out of multiple classes inside a div using xpath in selenium
You should use contains:
equals validates the attribute value is exactly equal to given value. As the attribute class value is "ng-untouched ng-pristine ng-invalid igx-input-group__input" ...
5
votes
Accepted
Unable to click button Selenium Webdriver 3
Try this xpath
//*[contains(@class,'btn btn-primary btn-lg btn-block pink button') and contains(@tabindex,'4')]
The xpath basically means : any element that has class attribute containing 'btn btn-...
5
votes
How to click a link when more than 1 exists?
When there are multiple instances and there is no other way to distinguish them* you can refer to the instance index, i.e. 'which one'.
CSS
a.instanceLink:nth-child(1)
or
a.instanceLink:nth-child(...
5
votes
Accepted
how to handle if xpath is same for multiple drop down
It might be issue of same level HTML code.
Solution :
1. For First Dropdown :
(//div[@name='expiryDate']/div/a/div[2]/i)[1]
2. For Second Dropdown :
(//div[@name='expiryDate']/div/a/div[2]/i)[2]
...
5
votes
How to handle web element(enable button) having same Xpath?
In my case, How I worked on this same scenario:
Suppose if you have 3 buttons with the same XPath-like in my DOM:
<input type="submit" id="button" value="Edit"/>
<input type="submit" id="...
5
votes
How to access a Hyper link using XPath
As far as i know xpath doesn't depends on any browser. Make sure you have created correct xpath it will work.
Second : It's depend on your tag which attribute it has and how efficient you are in ...
5
votes
How to write XPath if my ID is changing continuously?
Same like posted here.
//*[starts-with(@id,'post-')]/h3/a/time
OR
//*[contains(@id,'post-')]/h3/a/time
try with other attributes which are not changing continuously.
5
votes
How to find XPath inside <td>
Your text is dynamic, but it always contains .xlsx. So you can find the element with partial text matching.
Try this:
By.xpath("//td[contains(text(),'xlsx')]")
Or more specifically:
By.xpath("//td[...
5
votes
Accepted
How to write XPath under tag: strong
What you expect to query is actually placed not "under" strong tag, but "next to" strong tag. There is the text nodes that you should take. Hence you should take all the text nodes having string as ...
5
votes
How to find a button using both xpath and button text?
Using contains in xpath, for me is tricky. Tests are flaky with this approach. The better way is to use:
//button[text()='Some text']
Now, you compare/test the text of the button with expected text.
5
votes
Selenium web driver - how to select child elements
Using xpath to locate an element works regardless of the parents of the element. It doesn't matter if the parent is an li or a span, as long as your identifier is unique. So if you are using a CSS ...
5
votes
Accepted
Which Xpath is more suitable?
The two paths might give the same result on one sample document, but they will give different results on other documents. The one that is best is the one that gives the right results over a whole ...
4
votes
Correct CSS selector for selenium
If your edit class is unique on the page, then you can do .edit If you need to be a bit more specific, you could do more along the lines of .active.editing input.edit
The point is, theres no "right" ...
4
votes
How to use multiple condition in xpath?
You haven't explained the requirement very clearly, but perhaps the answer is
//div[h3='Admin' and h4='Group']
Note that you shouldn't use contains() to test whether a node contains some string, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
xpath × 341selenium-webdriver × 315
automated-testing × 132
java × 71
css-selectors × 28
selenium2 × 27
python × 22
browser-automation × 17
c# × 9
page-objects × 7
selenium-webdriver-c# × 7
exception × 7
css × 7
testng × 6
uiautomation × 6
appium × 5
javascript × 4
chromedriver × 4
robotframework × 4
elements × 4
jmeter × 3
protractor × 3
selenium-ide × 3
soapui × 3
test-design × 2