提要:Firefox引擎(谷歌引擎F12不好用了),選擇框內下拉選項,整體頁面下拉實現。
# 導入模塊
from selenium import webdriver
import random
from time import sleepXXX
username = ["XXX"]
number = ["XXX"]
phone = ["XXXXXXXXXXXX"]
temp = ["36.5"]
# 導入引擎網址
driver = webdriver.Firefox()
driver.get("http://xd7wszn1psfa9rfk.mikecrm.com/6bo2dGw")
# 填空
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[4]/div[2]/div/div[1]/input").clear()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[4]/div[2]/div/div[1]/input").send_keys(username[0])
# 給加載時間
sleep(2)
# 整體頁面下拉,執行JS語言
driver.execute_script('window.scrollBy(0,250)')
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/i").click()
sleep(1)
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/ul/li[4]/span").click()
# mouse = driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/i")
# ActionChains(driver).move_to_element(mouse).perform()
# driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[5]/div[2]/div/div/ul/li[4]/span").click()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[6]/div[2]/div/div/input").clear()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[6]/div[2]/div/div/input").send_keys(number[0])
driver.execute_script('window.scrollBy(0,250)')
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[8]/div[2]/div/div/div/input").clear()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[8]/div[2]/div/div/div/input").send_keys(phone[0])
driver.execute_script('window.scrollBy(0,250)')
# driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/i").click()
# driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/ul/li[10]").click()
# driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/i").click()
# driver,find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/ul/li[9]").click()
# 下拉雙選擇框
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[2]/i").click()
ul = driver.find_element_by_css_selector("div.fbc_mlItem:nth-child(2) > ul:nth-child(3)")
# 最后定位里面所有值
li = ul.find_elements_by_tag_name('li')
sleep(0.2)
# 選取想要的值
li[0].click() # 0代表選擇第一個值
sleep(1)
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[9]/div[2]/div/div[3]/i").click()
# 然后定位ul
ul = driver.find_element_by_css_selector("div.fbc_mlItem:nth-child(3) > ul:nth-child(3)")
# 最后定位里面所有值
li = ul.find_elements_by_tag_name('li')
# 選取想要的值
sleep(0.2)
li[0].click() # 0代表選擇第一個值
# 選擇框完畢
driver.execute_script('window.scrollBy(0,450)')
driver.find_element_by_css_selector("#opt203971237 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
sleep(0.5)
driver.find_element_by_css_selector("#opt203971239 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
sleep(0.5)
driver.find_element_by_css_selector("#opt203971241 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
sleep(0.5)
driver.find_element_by_css_selector("#opt203971243 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
# 雙選完畢
driver.execute_script('window.scrollBy(0,450)')
sleep(0.5)
driver.find_element_by_css_selector("#opt203971245 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
sleep(0.5)
driver.find_element_by_css_selector("#opt203971247 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[16]/div[2]/div/div/input").clear()
driver.find_element_by_xpath("/html/body/form/div/div[1]/div[2]/div/div/div[16]/div[2]/div/div/input").send_keys(temp[0])
sleep(0.5)
driver.find_element_by_css_selector("#opt203971249 > p:nth-child(1) > svg:nth-child(1) > circle:nth-child(1)").click()
sleep(0.5)
driver.execute_script('window.scrollBy(0,350)')
sleep(0.5)
driver.find_element_by_xpath("//*[@id='form_submit']").click()
print("Done...")