Ankit Choudhary
Ankit Choudhary

Reputation: 73

I am not able to write the css regular expression in selenium for a given line of code

The line of code for which i am writing the css regular expression is "<a href="https://mail.rediff.com/cgi-bin/login.cgi" title="Already a user? Sign in" class="signin" xpath="1">Sign in</a>"

The css regular expression which i wrote is -> "driver.findElement(By.cssSelector("//a[title*='Sign in']")).click();"

The syntax that i used was "//tagName[attribute*='value']"

Additional information I was able to write the regular expression x path without error

"driver.findElement(By.xpath("//a[contains(@title,'Sign in')]")).click();"

Thanks in advance

Upvotes: 0

Views: 93

Answers (2)

Justin Lambert
Justin Lambert

Reputation: 978

why are you writing a regular expression? when we work with web elements you need to inspect web elements and should work with locators like id, name, CSS selector, link text...etc

You just inspect and pick locators and use in your selenium

Upvotes: 0

Dixit_Autobot
Dixit_Autobot

Reputation: 39

the Syntax for CSS Selector using regular expression in selenium is

tagname[attribute* = 'value']

So change the locator as

a[title*='Sign in']

Upvotes: 1

Related Questions