The API for element operation is really convenient after reading.
1,sendKeys()
Fill in the content to the element
2,click()
Click element
3,clear()
Clear the content of the element, usually an input box
4,getAttribute()
Get the value of the specified attribute
5,get_property()
Get the value of the specified attribute
6,isDisplayed()
Whether the element is visible
7,isEnabled()
Is Yuanyuan disabled
8,isSelected()
Whether the element is selected
example:
-- coding: utf-8 --
from selenium import webdriver
import time
driver = webdriver.Chrome()
time.sleep(2)
Open url
driver.get(‘http://www.sterson.com.cn/test’)
time.sleep(2)
driver.find_element_by_id(“task_name”).send_keys(‘test1’)
time.sleep(1)
driver.find_element_by_id(“task_name”).clear()
n = driver.find_element_by_id(“task_name”).get_attribute(‘name’)
print n
c = driver.find_element_by_id(“task_name”).get_property(‘style’)
print c
9,Select
select can be used to select the value in the lower box select box
But first from selenium.webdriver.support.ui import Select
The thinking path is to find the drop-down selection element first and hand it over to select
Then get it through the method provided by select
select_by_value( ): select by value in option
select_by_index( ): select by subscript in option (subscript starts from 0)
select_by_visible_text( ): select by option text
deselect_all: Cancel all selected options
example:
-- coding: utf-8 --
from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
time.sleep(2)
Open url
driver.get(‘http://www.sterson.com.cn/test’)
time.sleep(2)
select = Select(driver.find_element_by_name(“task_type”))
time.sleep(1)
Select by the displayed value in the drop-down selection
select.select_by_visible_text("Design")
time.sleep(1)
Save value selection by drop-down selection
select.select_by_value(“requirement”)
time.sleep(1)
Subscript selection by drop-down selection
select.select_by_index(0)
Finally: a wave of software testing data sharing!
In the technology industry, you must improve your technical skills and enrich your practical experience in automation projects. This will be very helpful for your career planning in the next few years and the depth of your test technology mastery.
In the interview season of the Golden 9th and the Silver 10th, the season of job-hopping, organizing interview questions has become my habit for many years! The following is my collection and sorting in recent years, the whole is organized around [software testing], the main content includes: python automation test exclusive video, Python automation details, a full set of interview questions and other knowledge content.
May you and I meet and you will find something! If you want to exchange experience in software testing, interface testing, automated testing, and interviews. Follow WeChat public account:[Sad Spicy Strips]Receive a 216-page software test engineer interview book for free. And the corresponding video learning tutorials are free to share! Communication learning skirt:313782132
Recommend good articles:
What exactly should I learn in automated testing?
Which is more advanced, automated testing or manual testing?
Novice must see: How to write a qualified test case?
Python login interface test problem record and solution (dry goods)