findelements in selenium code example
Example 1: find elements in selenium
#In Python
#Let's say that we want to locate the h1 tag in this HTML:
#<html>
# <head>
# ... some stuff
# </head>
# <body>
# <h1 class="someclass" id="greatID">Super title</h1>
# </body>
#</html>
h1 = driver.find_element_by_name('h1')
h1 = driver.find_element_by_class_name('someclass')
h1 = driver.find_element_by_xpath('//h1')
h1 = driver.find_element_by_id('greatID')
Example 2: findelements in selenium
List<WebElement> elementName = driver.findElements(By.LocatorStrategy("LocatorValue"));
Example 3: selenium ways of finding
elementcss= driver.findElement(By.cssSelector('div.nav-search-input'))
Example 4: findelements in selenium
List<WebElement> listOfElements = driver.findElements(By.xpath("//div"));
Example 5: find elements in selenium
WebDriver driver = new ChromeDriver();
WebElement objWE;
objWE = driver.findElement(By.id("String of id attribute"));
objWE = driver.findElement(By.xpath("//*[@id="search"]/div[2]/div[6]/div[1]/div/div"));