DEV Community

Sree Lasya Vallabhaneni
Sree Lasya Vallabhaneni

Posted on

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

Top comments (0)