1

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.RveJvd.snByac is also used for Forgot email? button so this one is getting clicked.

Is there a way to combine class and the text 'Next' attributes of Next button?

Note : I have to use only CSS selector.

1 Answer 1

2

Css selectors do not allow selecting by inner text. To click that button with css you can just use:

driver.findElement(By.cssSelector("#identifierNext"))

or

driver.findElement(By.cssSelector("#identifierNext span"))
2
  • Hi thanks, it worked. Can you tell me difference between above two lines of code? In which case addition of tag (span) is helpful?
    – rushi
    Sep 20, 2018 at 2:04
  • It depends on which element does actually have the action assigned. In other words which element actually represents a button.
    – Alexey R.
    Sep 20, 2018 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.