from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import os
driver = webdriver.Chrome()file="file:///"+os.path.abspath("D:/jade/2..html")
driver.get(file)
driver.maximize_window()
time.sleep(6)# xpath定位# driver.find_element_by_xpath("//*[@id='ShippingMethod']/option[4]").click()
options = driver.find_elements_by_tag_name("option")# for option in options:# if option.get_attribute('value')=='9.03':# option.click()# 用数组的方式定位,要注意下标
options[3].click()
time.sleep(6)
driver.quit()
5. alert、confirm、prompt的处理
from selenium import webdriver
import time
import os
driver = webdriver.Chrome()file="file:///"+os.path.abspath("D:/jade/alert.html")
driver.get(file)
driver.maximize_window()
time.sleep(6)
driver.find_element_by_id("tooltip").click()
time.sleep(5)# 获得操作
alert = driver.switch_to.alert
# 关掉弹框
alert.accept()# alert的另一种用法from selenium import webdriver
import time
import os
driver = webdriver.Chrome()file="file:///"+os.path.abspath("D:/jade/send.html")
driver.get(file)
driver.maximize_window()
time.sleep(6)
driver.find_element_by_tag_name("input").click()
time.sleep(3)
alert = driver.switch_to.alert
alert.send_keys("龚俊!")
alert.accept()
time.sleep(6)
driver.quit()
DIV对话的处理
from selenium import webdriver
import time
import os
driver = webdriver.Chrome()file="file:///"+os.path.abspath("D:/jade/modal.html")
driver.get(file)
driver.maximize_window()
time.sleep(3)
driver.find_element_by_id("show_modal").click()
time.sleep(3)
driver.find_element_by_id("click").click()
time.sleep(6)
div = driver.find_element_by_class_name("modal-footer")
buttons = div.find_elements_by_tag_name("button")
buttons[0].click()
time.sleep(6)
driver.quit()