selenium

1. Definition and basic principle of selenium:

Selenium is a web application testing tool that supports multiple browsers and simulates real browsers.

2. Eight methods of positioning elements (the core of automated testing):

id, name ,classname,tag_name,link_text,xpath,partial_tink_text,css_selector

example:

self.driver = webdriver.Chrome(url)

two = self.driver.find_element(By.ID,'20320').click()

one =self.driver.find_elements_by_id('20320').click()

3. Get text, get ID, location, etc.

three=self.driver.find_elements_by_css_selector(' ')

print(three.text,three.id,three.location,three.tag_name,three.size)

4. Common problems:

a. Locating element failure one: Since the element has not been loaded, you can use the wait method (implicit waiting (the longest waiting time, wait for the page to complete and then perform the next step), explicit wait (after waiting for the required element to load Start the next step) Mandatory wait (regardless of the loading situation, you must wait for this, sleep)) implicitly_wait (), webDriverWait.until (), sleep ()

b. Locating elements is sometimes valid and sometimes invalid: relative address positioning

C. Too many scripts and low execution efficiency: reduce the number of operation steps; interrupt the page load without setting the timeout period without affecting the test

Guess you like

Origin www.cnblogs.com/mygodswangzi/p/12693462.html