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()
  • 相关阅读:
    Javascript实现局部刷新
    Javascript模块化开发-轻巧自制
    javascript面向对象实例
    Javascript兼容和CSS兼容总结
    隐藏关机按钮
    数组排序
    常用数组获取最新和第一个元素值
    php 操作redis 以及几个常用命令
    git 常用命令
    JSON.parse和JSON.stringify的区别
  • 原文地址:https://www.cnblogs.com/drizzlewithwind/p/5073484.html
Copyright © 2011-2022 走看看