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.

NarendraR
1,5731 gold badge17 silver badges35 bronze badges
asked Sep 19, 2018 at 3:06

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"))
answered Sep 19, 2018 at 7:42
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? Commented 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. Commented Sep 20, 2018 at 7:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.