zoukankan      html  css  js  c++  java
  • python selenium基本

    基本

    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()
  • 相关阅读:
    SQL 代码片段
    SQL
    Python List
    python_enumerate用法
    HashMap记录
    Brute Force(暴力算法)
    python解析html文件,提取标签中一个元素
    每五分钟统计一次数据
    grep
    expect
  • 原文地址:https://www.cnblogs.com/drizzlewithwind/p/5073484.html
Copyright © 2011-2022 走看看