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.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.



  • 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"))
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2