Automation QA Testing Course Content

Webdriver - WebElement Methods

 WebElement Methods:



 browserref.elementidentification.methodname();
 1)click():it is used to click on link, button,checkbox,listbox and radio button

 driver.findElement(By.locator("locatorvalue")).click();
       (or)
WebElement elename=driver.findElement(By.locator("locatorvalue"));
   elename.click();
   elename.sendKeys("ramesh");
ex:
driver.findElement(By.xpath("//button[@id='share-gotomeeting']")).click();
 2)submit():it is used to submit the buttons/on editbox (forms)
 driver.findElement(By.locator("locatorvalue")).submit();

 3)sendKeys("value"):it is used to type the value in a editbox
 driver.findElement(By.locator("locatorvalue")).sendKeys("value");
 //typing the firstname editbox value
 driver.findElement(By.name("firstName")).sendKeys("ramesh");

 4)clear():it is used to clear the content in the editbox
 driver.findElement(By.locator("locatorvalue")).clear();

 5)how to select an option from dropdown
 
 //1)identify the dropdown and assign it to a WebElement type varaible
 WebElement dropdownnameref=driver.findElement(By.locator("locatorvalue"));

 //2)fetch all the dropdown options using findElements API and
 tagName -option and store in List type collection
 List<WebElement>opts=dropdownnameref.findElements(By.tagName("option"));

 //for(datatype varname:collectionname){}
 for(WebElement o:opts){
 //print each dropdown option text
 System.out.println(o.getText());

 if(o.getText().equals("myoptiontext")){
 //select it
 o.click();
 break;
 }
 }
------------------------------------------------------------------------------------------------
5)how to select an option from listbox
 
 //1)identify thelistbox and assign it to a WebElement type varaible
 WebElement listbox=driver.findElement(By.locator("locatorvalue"));

 //2)fetch all the listbox options using findElements API and
 tagName -li and store in List type collection
 List<WebElement>optionsList=listbox.findElements(By.tagName("li"));

 //for(datatype varname:collectionname){}
 for(WebElement o:optionsList){
 //print each listbox option text
 System.out.println(o.getText());

 if(o.getText().equals("myoptiontext")){
 //select it
 o.click();
 break;
 }
 }



https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/WebElement.html?utm_medium=email&utm_campaign=elemental-selenium-java&utm_source=40-disabled-element&__s=t9ft8unh8y4zpgfcvtyh






No comments:

Post a Comment

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