Questions tagged [css-selectors]

CSS selectors are patterns that match against elements in a document tree. In a CSS rule, they are used to define styles for elements that match the pattern.

Filter by
Sorted by
Tagged with
0 votes
0 answers
33 views

How can I check that one element that has the same details as other elements is displayed/clickable using Selenium

I have a scenario that results in one of many validation icons appearing. I need to be able to assert that any one of them is visible but I have problems because of the other ones that remain hidden. ...
  • 11
0 votes
1 answer
478 views

How to write xpath or css for background-image value

I wanted to write Xpath or css for <div class="img"style="background-image:url(//cdn.shopify.com/shopifycloud/shopify/assets/no-image-2048-...
0 votes
1 answer
147 views

Does Selenium FindBy annotation accepts value from object repository?

I am wondering whether @FindBy annotation accepts xpath from properties or object repository file? and also please let me know , what is the practical approach ? a. Using Page object model having all ...
2 votes
3 answers
92 views

Why do HTML IDs need to be unique?

It is considered a good practice to have unique IDs of HTML elements. HTML standard specifies so: https://www.w3schools.com/htmL/html_id.asp You cannot have more than one element with the same id in ...
  • 4,089
0 votes
2 answers
809 views

Extract InnerHTML from

Is there a way that I can extract the following data in Chrome Devtools Console. Currently I do the following in the console of the chrome devtool: $x("//a") I get a list with all the a ...
1 vote
1 answer
522 views

Automating a comment delete on FB with Selenium

I am trying to automate deleting my old comments on posts I've made on FB. Im using Selenium with python to achieve this. I am currently having trouble dealing with pressing the hidden buttons (1 &...
  • 11
6 votes
3 answers
818 views

Are test-specific selectors a good idea?

In the past I had thoughts for more elegant HTML item selection. I found there may be a better approach, in contrast to "traditional" one. Old school way: .site-body .menu-box > li.item a.link ...
  • 177
2 votes
1 answer
228 views

The value from the table is different using Xpath and CSS selectors

Test url=https://www.cricbuzz.com/live-cricket-scorecard/22585/aus-vs-nz-1st-odi-new-zealand-tour-of-australia-2020 I am trying to get the title of a table using the below code: Code snippet: ...
0 votes
1 answer
95 views

Jmeter- I am unable to sign up using CSS Selector extractor using Jmeter- Please Help

I am working on Jmeter for testing a Magento application. I am using CSS Selector Extractor for extracting the form_key element during sign up. I have provided the following parameters in CSS selector ...
0 votes
2 answers
244 views

Parameters for CSS Selector not working in Jmeter

I am working on Jmeter for testing a Magento application while using the CSS selector extractor and providing the following information. Please let me know if the parameters are correct. In the post ...
  • 113
1 vote
2 answers
294 views

Can some one help me to find the CSS selector for highlighted item

Could someone help me to identify the correct csslocator for the second span element in the below image: I tried the below locators but was not able to succeed, is there anything wrong with the ...
  • 2,093
0 votes
4 answers
1k views

Not able to find the unique xpath for an element in expedia.com using Selenium

I am trying to find the unique xpath for elements in the "travelers" pop option in the home page of expedia.com When I give the following xpath "//div[contains(@class,'gcw-menu')]/div/div1/div2/div[4]...
0 votes
1 answer
108 views

Finding an item in a table - Selenium scripts

I need to select/click an item from the table. I'm new/beginner to selenium. when I inspect the individual property, it has: <a id = "rpn" style=”cursor: pointer”, ng-click=”grid.appScope....
  • 1
3 votes
4 answers
1k views

locating element by id or css, which is faster?

If there is an id available for an object in a page, find element by ID or CSS - which is faster? element(by.id("btnButtonID")) OR element(by.css("#btnButtonID") Since we can identify any objects ...
0 votes
3 answers
4k views

Unable to find element with css selector == input[name='username']

WebElement username = driver.findElement(By.cssSelector("input[name='username']")); The statement mentioned above was working before but right now concerned element can't be captured and error ...
0 votes
1 answer
222 views

how can i capture src in xml by using cssSelector or Xpath?

how can i capture src in following xml by using cssSelector or Xpath ? <INPUT src="/TelsimGlobal/Menu/image3.gif" type=image> i tried to execute following ones but always faced with "Unable to ...
1 vote
3 answers
4k views

Select element by containing text without XPath in Selenium

There is a great discussion on what makes a good Selenium locator here. It seems many testers prefer CSS to XPath for locators, for various reasons. And that goes for me, too. But, it is often ...
  • 4,089
0 votes
1 answer
585 views

Writing selenium tests againgst bootstrap Checkboxes

I have currently a big Problem to click on a Checkbox in a bootstrap designed GUI. In Html it appres like this: Does someone know how to press the Button of this checkbox? Because the controls are ...
0 votes
2 answers
2k views

Selenium with Google search results

When you search for something in Google and get the results, it is not easy to locate the elements, using Selenium, since Google uses classes like <div class="kno-ecr-pt kno-fb-ctx gsmt"> ...
0 votes
1 answer
959 views

Want to test ebay site login without using Xpath

I want to test the Ebay site login, without using Xpath. It is not working, right now. I tried for hours to make this work. Please tell me what I am doing wrong and how to fix it. This is what I am ...
1 vote
1 answer
61 views

Same element locators under different parents

This is more of a "code review" question but it is very SQA specific so posting it here. There are two different menus on a page: "left" and "right" both containing "save" and "cancel" buttons with ...
  • 11.4k
2 votes
2 answers
2k views

How to Select a value from Dropdown using Selenium WebDriver (Java) having input and div but not select tag?

I am trying to select a value from a dropdown. When I inspect that dropdown, I cannot see the select Tag, instead it was designed with combination of input and div tags. Can anyone suggest a way how ...
4 votes
1 answer
5k views

Selecting second instance of identically named class using CSS Selectors

Given the following snippet: <div class="page-block__content"> <div class="page-cards"> <div class="statement"> <div class="statement-text"> <p>Some ...
  • 383
1 vote
1 answer
804 views

How to use class and text attribute together in CSS selector in selenium

I'm working on this site. There is a Next button. I want to click it using CSS selector only. I'm using below code to get the element: driver.findElement(By.cssSelector("span.RveJvd.snByac")) span....
  • 11
1 vote
2 answers
7k views

Locating Inner Text with CSS or Xpath in Amazon

I am teaching myself automation with Selenium web driver, and thought a good way was to learn off an ecommerce site such as Amazon. I am trying to locate inner text with CSS and used the following to ...
  • 13
4 votes
3 answers
4k views

syntax for css selector class attribute combination

I have bunch of elements with class X. some elements have class Y also (ie both X and Y) how do I select set of elements only have X with partial class name? below is my example HTML <td class="...
  • 487
2 votes
2 answers
3k views

Can we use css properties (like background-color) for locating an element when that property is not part of the element attributes

Can we use css properties (like background-color) for locating an element when that property is not part of the element attributes? Like If I have to get the xpath or css of this element, either I ...
0 votes
5 answers
3k views

How to locate "Login" button of Flipkart bootstrap login page? I tried in many ways, but still unable to locate element

Below are three options I tried, but I'm not able to locate Login button. When I tried using seleniumIDE, I got this xpath=(//button[@type='submit'])[2] But its not working in Webdriver. Can someone ...
  • 1
5 votes
4 answers
51k 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 ...
  • 111
0 votes
3 answers
1k views

css locators - when should I use ">" vs. " "(space)

Some css expressions I see are like this div > div > span > h1 while others use div div span h1 What are the advantages / disadvantages to using one approach vs the other?
0 votes
1 answer
411 views

Element not visible on IE 11with nightwatch

We are using Nightwatch and working with Page objects. The tests are running without any issue on Chrome but element cannot be found on IE 11. We use css selector and custom tags (named data-testid) ...
  • 1
0 votes
1 answer
200 views

Are SelectById, SelectByClass and SelectByName just special cases of general SelectByTag?

2 questions in 1: 1) In all the Selenium tutorials they divide the ways of finding elements in the way like: 1. By ID 2. By CLASS 3. By NAME 4. By TAGNAME 5. By CSS Selector 6. By Link 7. By XPath I ...
  • 103
3 votes
2 answers
2k views

Using Protractor to test AngularJS frontend- how do I get HTML DOM objects that are nested within other objects?

I am working on the development of an AngularJS app, and have recently been asked to look at integrating some automated testing into our development process. I have not used automated testing at all ...
10 votes
2 answers
809 views

Detecting complicated CSS selectors

This is a follow-up to What makes a good selenium locator? Motivation I've been thinking about detecting the complexity of CSS selectors statically. The scope I'm working in is both test-automation ...
  • 11.4k
33 votes
7 answers
21k views

What makes a good selenium locator?

When automating UI tests with Selenium, it is often not absolutely clear what method and what locator to use to locate an element. Some locators are less reliable, less readable than others. And, ...
  • 11.4k
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="...
  • 41
2 votes
4 answers
19k views

How do I use a combination of attributes to select a button in Selenium?

I'm trying to get selenium to select a simple button that says next. I've tried XPath, CSS, and linktext and it still will not select it for me saying it cannot locate the element. Here is the code. ...
  • 375
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 || ...
  • 375
4 votes
3 answers
654 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 ...
0 votes
1 answer
505 views

How to give multiple Class names with or condition in Coded UI search properties [closed]

this.SearchProperties[WinWindow.PropertyNames.ClassName] = ".class1 or .class2";
3 votes
1 answer
4k views

XPath 'following', 'preceding' method equivalent in CSS selecor selenium

I am converting my project element library from xpath to CSS. Some xpath expression written using 'following' and 'preceding' method. Like below. //div[@id='dashboard_right_now']/following::a[...
4 votes
3 answers
108k 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
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?
  • 33
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 ...
  • 10.4k
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 ...
0 votes
1 answer
357 views

Finding column with certain text works using xpath but fails with cssSelector

I was trying to locate table column containing text 'Name', and it fails while using cssSelector with 'Unable to locate element' but works with XPath. I tried all the 3 below options with different ...
1 vote
1 answer
3k views

Dynamic ID selecting text from dropdown

I have a situation I'm trying to handle. I am using webdriver, C#. The image above is the dropdown I want to select from. This is how it works, to select from the element, first click it and a text ...
  • 151
5 votes
2 answers
25k views

Selenium - Find exact text match using CSS locators

According to A way to match on text using CSS locators, we should be able to use "^$" to find exact text match using CSS locators. But with: <div class="item"><div class="text">Trouble&...
  • 51
33 votes
6 answers
303k 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 ...