Shahab
0
Q:

find element vs find elements in selenium

Differences between findElement and findElementS method?
    --> findElement():
     
      -It does returns SINGLE web element.
      - Return type: WebElement
      - If it cannot find a web element, it throw - NoSuchElementException
          
   
   --> findElements():
      - Returns a List of WebElements
      - Return type: List<WebElement>
1
#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')
1
//required imports 
WebDriver driver = new ChromeDriver();
WebElement objWE;
//There are many way most common are id and xpath
objWE = driver.findElement(By.id("String of id attribute"));
//To find the xpath easily hit F12 and right click the element you want
//and copy xpath then paste it
objWE = driver.findElement(By.xpath("//*[@id="search"]/div[2]/div[6]/div[1]/div/div"));
0
List<WebElement> listOfElements = driver.findElements(By.xpath("//div"));
0

New to Communities?

Join the community