selenium3-book-code

Stars
101

Selenium3--Python

ppage, 10

p46

find_element_by_xpath("/html/body/div/div[2]/div/div/div/from/span/input")
find_element_by_xpath("/html/body/div/div[2]/div/div/div/from/span[2]/input")
find_element_by_xpath("/html/body/div/div[2]/div/div/div/form/span/input")
find_element_by_xpath("/html/body/div/div[2]/div/div/div/form/span[2]/input")

p47

find_element_by_xpath("//span[@class='bg s_ipt_wt']")
find_element_by_xpath("//span[@class='s_ipt_wt']")

p48

  • text()
find_element_by_xpath("//a[text(), '']")
find_element_by_xpath("//a[text()='']")
find_element_by_xpath("//a[contains(text(), '')]")
find_element_by_xpath("//a[contains(text()='')]")

p54

submit()

seearch.submit()
search_text.submit()

p60

visibility_of_element_located``presence_of_element_located

  • visibility_of_element_located
  • presence_of_element_located DOM

p69

4.12

w3school

from selenium import webdriver
from selenium.webdriver.support.select import Select
from time import sleep

driver = webdriver.Chrome()
driver.get('https://www.w3school.com.cn/tiy/t.asp?f=eg_html_select')
driver.set_page_load_timeout(2)
driver.set_script_timeout(2)

# 
driver.switch_to.frame("iframeResult")

# select
sel = driver.find_element_by_tag_name("select")

# value="saab"
Select(sel).select_by_value('saab')
sleep(2)

# <option>Opel</option>
Select(sel).select_by_visible_text("Opel")
sleep(2)

# 
Select(sel).select_by_index(3)
sleep(2)

driver.quit()

p77 ~ 78

4.17 HTML5 ()

ChromeChromiumfirefoxJSH5

p79 ~ 81

4.18

  1. ()
  2. ""
from time import sleep
from selenium import webdriver


driver = webdriver.Chrome()

driver.get("http://www.jq22.com/yanshi4976")
driver.set_page_load_timeout(2)
driver.set_script_timeout(2)

sleep(2)
driver.switch_to.frame("iframe")
driver.find_element_by_id("appDate").click()

# 
dwwos = driver.find_elements_by_class_name("dwwo")
year = dwwos[0]
month = dwwos[1]
day = dwwos[2]

# 
action = webdriver.ActionChains(driver)
action.click_and_hold(year).move_by_offset(0, 100).perform()
action.reset_actions()

# 
action2 = webdriver.ActionChains(driver)
action2.click_and_hold(month).move_by_offset(0, 150).perform()
action2.reset_actions()

# 
action3 = webdriver.ActionChains(driver)
action3.click_and_hold(day).move_by_offset(0, 150).perform()
action3.reset_actions()

p86

5.3

126

p92

5.4.3 xml

config.xml

    <platform>
        <os>Windows</os>
        <os>Linux</os>
        <os>macOS</os>
    <platform>
    <platform>
        <os>Windows</os>
        <os>Linux</os>
        <os>macOS</os>
    </platform>