This property is used to fetch the text on a given WebElement.It doesn’t take any argument and it returns a string value.
ele = driver.find_elements(By.CLASS_NAME,"breadcrumb-item") for menu in ele: print(menu.text)
This method is used to get the tag name of a WebElement.It doesn’t take any argument, but it returns a string value.
element = driver.find_element(By.ID,"user_input") print("Tag Name of id value 'user_name' :",element.tag_name)
This method is used to get attribute value for a given WebElement.It doesn’t take any argument and it returns string value.
element = driver.find_element(By.ID,"user_input") print("text :",element.get_attribute('value'))
Attributes are Id, name ,value,class by using getAttribute() method you can fetch the value of those attributes.
This property is used to get the dimensions such as width and height for a given WebElement.It doesn’t take any argument and it returns the value of width and height of a webelement.
element = driver.find_element(By.ID,"user_input") element_size = element.size print("Size of element of id 'user_input' :", element_size)
This property is used to find the location of WebElement in a current webpage.It doesn’t take any argument and it returns x y coordinates of webelement.
element = driver.find_element(By.ID,"user_input") element_location = element.location print("Location of the element on webpage : ", element_location)
This method is used to find the css property value for a given WebElement. Css properties such as background-color, font-family,font-size etc.It takes string argument and it returns string value.
element = driver.find_element(By.ID,"user_input") css_property = element.value_of_css_property("font-family") print("CSS of : ",css_property)
WebElement_Properties.py
from selenium import webdriver import time from selenium.webdriver.common.by import By driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe") driver.get("http://www.dummypoint.com/seleniumtemplate.html") time.sleep(2) ele = driver.find_elements(By.CLASS_NAME,"breadcrumb-item") for menu in ele: print(menu.text) time.sleep(2) element = driver.find_element(By.ID,"user_input") element.send_keys("Skill2Lead") time.sleep(2) print("text :",element.get_attribute('value')) print("Tag Name of id value 'user_name' :",element.tag_name) element_size = element.size print("Size of element of id 'user_input' :", element_size) element_location = element.location print("Location of the element on webpage : ", element_location) css_property = element.value_of_css_property("font-family") print("CSS of : ",css_property) time.sleep(5) driver.quit()