Python Automation Test - Chapter 2: Selenium

一、环境准备

1. install selenium:

pip install selenium

Python Automation Test - Chapter 2: Selenium_第1张图片

2. install chromedriver:

brew install chromedriver

Python Automation Test - Chapter 2: Selenium_第2张图片

3. confirm the version of chromedrive:

chromedriver --version

Python Automation Test - Chapter 2: Selenium_第3张图片

二、实例2

test google search in selenium

# 1. go to google.com
# 2. type in a search 'puppies'
# 3. submit or enter the search
# 4. assert we got a search page for puppies

Python Automation Test - Chapter 2: Selenium_第4张图片

1. how to find search box element in dev tool?

Python Automation Test - Chapter 2: Selenium_第5张图片 (找到element)

2. submit or enter the search:

the name of "google search" element is unique:

Python Automation Test - Chapter 2: Selenium_第6张图片 

to verify, we can execute this code in console:

$("[name='btnK']") 

Python Automation Test - Chapter 2: Selenium_第7张图片 

3. example:

Python Automation Test - Chapter 2: Selenium_第8张图片

4. result:

Python Automation Test - Chapter 2: Selenium_第9张图片 

三、statsroyale.com:

1. find cards page:

Python Automation Test - Chapter 2: Selenium_第10张图片

 verify it's unique:

Python Automation Test - Chapter 2: Selenium_第11张图片

2. find the element of the specific image:

 

$("[href*='Ice+Spirit']")

Note: ' *= ' means 'contains'

(want to get the href that contains the word "ice spirit")

Python Automation Test - Chapter 2: Selenium_第12张图片 

3. example:

Python Automation Test - Chapter 2: Selenium_第13张图片

4. result:

Python Automation Test - Chapter 2: Selenium_第14张图片 

 

 

 

 

 

 

你可能感兴趣的:(python)