Automation QA Testing Course Content

WebDriver findElement() Methods

findElement(By.locator("locatorvalue")):it finds the first webelement in a webpage based on the given locator
syntax:
//datatype elementname=webdriverfindelementmethod();
WebElement elelementName=driver.findElement(By.locator("locatorvalue"));
WebElement is an interface, it is a datatype for the webelements
Note:findElement always returns WebElement type element

WebElement signin_link=driver.findElement(By.linkText("Sign in"));

WebElement search_btn=driver.findElement(By.className("newsrchbtn"));


findElements(By.locator("locatorvalue")):it finds all 
elements in a current page based on given locator and stores in a list type collection
List<WebElement>collectionname=driver.findElements(By.localtor("locatorvalue")); 
returns collection type List


how can you fetch all elements from particular element/section;?

1)identify the element/section
WebElement elementname=driver.findElement(By.localtor("locatorvalue"));

2)fetch all webelements from particular element(step 1)
List<WebElement>collectioname=elementname.findElements(By.locator("locatorvalue"));





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.