python selenium基本

python

基本

from selenium import webdriver

import re

driver = webdriver.Firefox()

driver.get('https://www.google.com')

main_window = driver.current_window_handle

driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')

element = driver.find_element_by_xpath("/html/body/div[2]/div[1]/table/tbody/tr[2]/td[6]")

actions = ActionChains(driver)

actions.move_to_element(element1)

actions.perform()

path = ‘/html/body/div[2]/div/ul/li/a'

color_rgb = driver.find_element_by_xpath(path).value_of_css_property('color')

rgb_values = re.match( r'\w+\((.*), (.*), (.*), \d+\)', color_rgb)

red = rgb_values.group(1)

green = rgb_values.group(2)

blue = rgb_values.group(3)

alert = driver.switch_to_alert()

print alert.text

required_text = "Login failed"

if alert.text != required_text:

print 'ERROR'

alert.accept()

while(driver.find_element_by_xpath("/html/body/div/form/div[1]/input").is_displayed()):

driver.find_element_by_xpath("/html/body/div/form/div[1]/input").click()

if not driver.find_element_by_id('checkitem').is_selected():

driver.find_element_by_id('checkitem').click()

driver.find_element_by_id('username').clear()

key = driver.find_element_by_xpath('//tr[@class="dataView otr"][%d]/td[1]'%i).text.strip()

以上是 python selenium基本 的全部内容, 来源链接: utcz.com/z/388595.html

回到顶部