Selenium WebElement Methods(sendKeys(),getAttribute(),getTagName(),getSize(),getPosition(),getCssValue(String PropertName))
In Selenium WebDriver when ever we try to idenfity the elements we get the return type as WebElement.
In the below example we are going to explore the different methods available in the WebElement:
HTML Source Code for textbox in Facebook:
<input type="text" class="inputtext _58mg _5dba _2ph-" data-type="text" name="firstname" aria-required="1" placeholder="" id="u_0_1" aria-label="First name"/>
SELENIUM WEBDRIVER CODE:
WebElement element = driver.findElement(By.id("u_0_1"));
Actions performed on the Textbox
element.sendKeys("firstname");
element.clear();
element.click();
element.getAttribute("value");
element.getTagName();
element.getSize();
element.getPosition();
element.isDisplayed()
element.isEnabled()
element.getCssValue(String propertyName)
Ex: The propertyName can be background-color.
Actions performed on the button
element.click();
element.submit();
Difference between click() and submit() methods.
If the button is available in the html form then we have to use
submit() method else we have to use click() method.
Refer to the screenshot as displayed below for more information for submit() method:
Misc Information about the WebElement
Apart from the methods mentioned we can findElement() and findElements() methods available.
element.findElement(By)
element.findElements(By)
In the below example we are going to explore the different methods available in the WebElement:
HTML Source Code for textbox in Facebook:
<input type="text" class="inputtext _58mg _5dba _2ph-" data-type="text" name="firstname" aria-required="1" placeholder="" id="u_0_1" aria-label="First name"/>
SELENIUM WEBDRIVER CODE:
WebElement element = driver.findElement(By.id("u_0_1"));
Actions performed on the Textbox
element.sendKeys("firstname");
element.clear();
element.click();
element.getAttribute("value");
element.getTagName();
element.getSize();
element.getPosition();
element.isDisplayed()
element.isEnabled()
element.getCssValue(String propertyName)
Ex: The propertyName can be background-color.
Actions performed on the button
element.click();
element.submit();
Difference between click() and submit() methods.
If the button is available in the html form then we have to use
submit() method else we have to use click() method.
Refer to the screenshot as displayed below for more information for submit() method:
Misc Information about the WebElement
Apart from the methods mentioned we can findElement() and findElements() methods available.
element.findElement(By)
element.findElements(By)
0 comments:
Post a Comment