DEV Community

Sree Lasya Vallabhaneni
Sree Lasya Vallabhaneni

Posted on

4

A handy selenium selector syntax in different languages

Java:
driver.get('http://google.com')
ID - driver.findElement(By.id("ui-div"));
CSS - driver.findElement(By.cssSelector("text-t"));
Xpath - driver.findElement(By.xpath("//div[@id ='ui-div']"));
Name - driver.findElement(By.name("element name"));
Link - driver.findElement(By.link("link"))
TagName - driver.findElement(By.tagName("tag name"))

Python:
driver.get('http://google.com')
ID - driver.find_element_by_id("idname")
CSS - driver.find_element_by_css_selector('body > div > button')
Xpath - driver.find_element_by_xpath('body/name')
Name - driver.find_element_by_name('username')

JavaScript:
driver.get('http://google.com')
ID - driver.findElement(webdriver.By.id("password"));
CSS - driver.findElement(webdriver.By.css('body > div > div));
Xpath - driver.findElement(webdriver.By.xpath('body/name'));
Name - driver.findElement(webdriver.By.name('q'));

c#
driver.Navigate().GoToUrl("http://www.google.com");
ID - driver.FindElementById("droppable");
CSS - driver.FindElementByXPath("//[@id =\"droppable\"]/p")
Xpath - driver.FindElementByCssSelector("div.form-actions > button")
Name - driver.FindElementByName("password")

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →