Skip to content
This repository was archived by the owner on Nov 29, 2018. It is now read-only.

css pseudo-class :contains() no longer allows anchors #1547

Closed
lukeis opened this issue Mar 2, 2016 · 5 comments
Closed

css pseudo-class :contains() no longer allows anchors #1547

lukeis opened this issue Mar 2, 2016 · 5 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1547

What steps will reproduce the problem?
1. Using Selenium Server 2.0b3 (Selenium component, not webdriver), navigate to www.google.com
2. Attempt to click on a link using the locator "css=a:contains('^About Google$')"

What is the expected output? What do you see instead?
Expect: Click on the link "About Google"
Actual: console reports "ERROR: Element css=a:contains('^About Google$') not found"

What version of the product are you using? On what operating system?

selenium-server-standalone-2.0b3 on Windows 7 64-bit.
This issue does not repro (i.e. it works as expected) with selenium-server-1.0.3 on
the same hardware.

Please provide any additional information below.

This is not a widely documented feature of Selenium but I use it quite extensively.
I found out about it via the Sauce Labs blog. See the "Matching by inner text section"
here:
http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/
I use ruby (selenium-client), some simplified code to repro:

page.open('http://www.google.com')
page.click("css=a:contains('^About Google$')")

Note: if you remove the anchors ^ and $ from the locator the code will work, but this
allows for loose rather than exact matching.

Reported by dara.lillis on 2011-04-13 21:44:31

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

The formatter seems to have swallowed a closing parenthesis after 'http://www.google.com'
in my example code.

Reported by dara.lillis on 2011-04-13 21:47:36

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by dawagner on 2011-04-22 23:40:18

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

I don't see how this issue is a duplicate of 987.

Reported by dara.lillis on 2011-04-25 19:42:01

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

contains isn't a valid CSS3 selector; because of this several browsers don't natively
support contains, so Selenium (and WebDriver) don't claim to support it.

In Selenium, I believe link='About Google' is what you're looking for, and in WebDriver
driver.find_element(:link_text, 'About Google')

Reported by dawagner on 2011-04-26 00:19:21

@lukeis
Copy link
Member Author

lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 18:12:39

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 2, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant