WebElement常用属性
1.id 标示
2.size 宽高
3.rect 宽高和坐标
4.tag_name 标签名称
5.text 文本内容
WebElement常用方法
1.send_keys() 输入内容
2.clear() 清空内容
3.click() 点击
4.get_attribute() 标签名称
5.is_selected() 是否被选中
5.is_enabled() 是否被选中
7.is_displayed() 是否显示
8.value_of_css_property() css属性值
补充:如何通过在from表单里面进行定位
from selenium import webdriver
from selenium.webdriver.common.by import Byclass TestCase(object):def __init__(self):self.driver = webdriver.Chrome()self.driver.get("https://sahitest.com/demo/linkTest.htm")self.driver.maximize_window()def test_webelement_prop(self):e = self.driver.find_element(By.ID,"t1")print(e.id) print(e.size) print(e.rect) print(e.tag_name) print(e.text) def test_webelement_method(self):e = self.driver.find_element(By.ID, "t1")e.send_keys("test")print(e.get_attribute("type")) print(e.get_attribute("value"))print(e.get_attribute("name"))e.clear()print(e.value_of_css_property("font")) print(e.value_of_css_property("color"))def test_locoted_from(self):from_element=self.driver.find_element(By.XPATH,"/html/body/form[1]")from_element.find_element(By.TAG_NAME,"input").send_keys("input")
if __name__ == '__main__':case = TestCase()case.test_locoted_from()