28
votes
Accepted
What makes a good selenium locator?
Good question, especially if people will read it and stop using XPath (I am not holding my breath).
Selenium best practices mentions order of preference: id > name > css > xpath
Mozilla explains why ...
20
votes
What makes a good selenium locator?
Choosing a good locator is very important to do carefully - it will define how reliable, readable, maintainable and durable your tests are going to be; how much dependent on the UI and design changes ...
9
votes
What makes a good selenium locator?
I think most answers are pretty good, but I would like to focus a bit on the higher level of these questions and not the details.
What makes a good Selenium locator?
Readability: Shorter is better,...
8
votes
What makes a good selenium locator?
For my money it is CSS Locators. Uses ID and/or class if there is one and uses position otherwise. Plus it is super easy to get Chrome to give you a CSS selector and test it in the console tab of ...
6
votes
What makes a good selenium locator?
What makes a good selenium selector?
uses css
unique
robust
short
descriptive
Given those quality attributes, in practice that translates into:
Favor css over xpath for readability
e.g. favor "form....
4
votes
How to locate Facebook POST button using Java Selenium WebDriver?
If you are asking about this post button - try below code to click on post button.
for this-
WebElement postBtn = driver.findElement(By.xpath("//button[contains(.,'Post')]"));
postBtn.click();
OR
...
3
votes
Accepted
How do I identify a specific <div> by id with Selenium?
// tagNameString is equal to "storytext"
driver.findElements(By.tagName(tagNameString));
What you are actually asking Selenium to do is to find all "storytext" elements. Selenium will be looking for ...
3
votes
What makes a good selenium locator?
Explaining a bit more on how you can make your selector robust
Bad selector
If this is the selector you use
.content > table > tbody > tr:nth-child(2) > td.cell > input#email
And the ...
2
votes
A testing tool that determines whether a section of HTML matches a certain style?
The most solid approach would be to render it, and see what's the style; and that's easier than it sounds :)
There's a Javascript method getComputedStyle which should do the heavy lifting for you - ...
2
votes
XPATH FACEBOOK How can i get xpath or css selector ? - selenium/java
String option = "esporte interativo";
String locator = "//ul[@id='facebar_typeahead_view_list']" +
"/li[contains(normalize-space(.), '" + option +"')]";
driver.findElement(By.xpath(...
2
votes
What are the debug tools that i can use for GUI Automation on Internet Explorer?
Have you tried the IE developer tools (F12)?
2
votes
Accepted
how can i capture src in xml by using cssSelector or Xpath?
It is not an image (IMG) or a link (A) tag, it is a INPUT tag:
By.xpath("//input[@src='/TelsimGlobal/Menu/image3.gif']")
2
votes
Accepted
how to Iterate a List of links?
"Books" is a single list item, which contains a new list with the categories. So you need to go deeper into that list like this:
//div[@class='side_categories']/ul/li/ul/li/a
In test code, it should ...
1
vote
Selenium C# Locate Both Data QA Attribute And CSS Class
By.XPath("//*[@data-qa='homephone-update' and @class='ng-invalid']");
Try this
1
vote
Accepted
Verify Text using CSS or Xpath
The way you are using cssSelector to find an element using some text, It doesn't allow in cssSelector. There is no such method in CSS selector to locate an element using text so for that you have to ...
1
vote
Can't find any element using CSS selector with Selenium on Python
In situations like this, you should try working up and seeing if the more easily available elements can be found instead. A fairly standard way check is to confirm the title element is found and ...
1
vote
Can't find any element using CSS selector with Selenium on Python
The beginning of the CSS Selector is wrong.
Searching for .freesim-text-last button span you will find two elements.
Pick the one which you're trying to reach using the follow:
.freesim-text-last ...
1
vote
What makes a good selenium locator?
Ideally, the most preferred locator to recognize a web-element in Selenium WebDriver is ID.
Reasons?
It is short.
It is fastest compared to other locators since in the background all
it needs to do ...
1
vote
Testing CSS styles and design elements of website
If you want to automate this, I'm aware of two possibilities:
As suggested by Bobby231, you could use a visual testing tool such as Depicted (open source) or Applitools (closed source) to check the ...
1
vote
Testing CSS styles and design elements of website
Cribbing from an answer from https://stackoverflow.com/questions/7754469/export-css-of-dom-elements:
Not a direct answer, but with Chrome Developer Tools, you can click
inside Styles or Computed ...
1
vote
A testing tool that determines whether a section of HTML matches a certain style?
You will need to write some custom code. There are multiple ways to do this depending on your end goal. There is a code only approach like what YuZhang suggests in utilizing a python library for ...
1
vote
How to locate Facebook POST button using Java Selenium WebDriver?
Inspect the element with below xpath locator :
By.xpath("//*[contains(@class, '_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft') and @type='submit']");
Hope it will help resolve your problem.
1
vote
Can Css Selector be used to write customized path using tag name traversing?
form.form-horizontal > div:nth-child(3) > div > input
I suggest spending 20 minutes here
1
vote
What CSS locator can I use when there is no good ID, Name or Class?
Assuming this is unique on the page, you should be able to identify and click the same element using CSS = '[data-testid="media-attachment-selector"]'. (You could also pre-fix the element with a to ...
1
vote
CSS visual regression - do I need to store screenshots in git repository?
I would say No. You dont need to keep these files versioned. Ie TestImage1.png will never be updated or changed, as such I would suggest you store them alongside your test results. At this point ...
1
vote
CSS visual regression - do I need to store screenshots in git repository?
Data is always better if it is stored in a central location where it is accessible to all the team members.
It may happen that your team is distributes in different geographical location. In that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
selenium-webdriver × 21css × 21
xpath × 7
java × 5
automated-testing × 4
browser-automation × 3
css-selectors × 3
python × 2
selenium2 × 1
c# × 1
page-objects × 1
web-application × 1
regression-testing × 1
uiautomation × 1
continuous-integration × 1
chrome × 1
firefoxdriver × 1
dynamic-testing × 1
firebug × 1