zoukankan      html  css  js  c++  java
  • 鼠标操作

    '''
    鼠标操作
    context_click 右键操作
    drag_and_drop 拖拽操作,拖动某一个元素到另外一个区域,然后释放按键
    move_to_element() 鼠标悬停
    perform() 执行鼠标操作
    引入 ActionChains类
    from selenium.webdriver.common.action_chains import ActionChains
    AC.方法名 1()....perform()

    select类-下拉框操作
    selenium提供了select类来处理selet/option
    引入类
    from selenium.webdriver.support.ui import Select
    选择下拉列表值
    1.通过下标选择:select_by_index(index)从0开始
    2.通过value属性:select_by_value(value值)
    3.通过文本内容:select_by_visible_text(文本内容)
    '''
    from selenium.webdriver.support.ui import Select#引入操作下拉框的类
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    import time
    from selenium import webdriver
    # zfwx = webdriver.Chrome()
    # zfwx.get("http://www.zfwx.com")
    # #1.先定位要操作的元素
    # ele=zfwx.find_element_by_xpath('//a[@class="menu-list-first"]')
    # sj=zfwx.find_element_by_xpath('//li[@class="listul-li"]//a[text()="司法鉴定"]')
    # #2.调用鼠标操作方法最用调用perform()方法执行鼠标操作
    # ActionChains(zfwx).move_to_element(ele).click(sj).perform()#悬浮后可以直接点击操作
    # # zfwx.find_element_by_xpath('//li[@class="listul-li"]//a[text()="司法鉴定"]').click()

    baidu = webdriver.Chrome()
    baidu.get("http://www.baidu.com")
    #1.先定位要操作的元素
    ele=baidu.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_settingicon"]')

    #2.调用perform()执行鼠标操作
    ActionChains(baidu).move_to_element(ele).perform()

    #3.等待元素出现
    loc = (By.XPATH,'//a[text()="高级搜索"]')
    WebDriverWait(baidu,10).until(EC.visibility_of_element_located(loc))


    #4.出现后点击高级搜索(两种点击方式)
    #baidu.find_element_by_xpath('//a[text()="高级搜索"]').click()
    baidu.find_element(loc[0],loc[1]).click()#直接调用定位表达式

    #下拉框处理 == sekect/option这样的元素 使用webdriver Select 类来处理

    #1.找到select元素
    WebDriverWait(baidu,15).until(EC.visibility_of_element_located((By.XPATH,'//select[@name="ft"]')))
    sel=baidu.find_element_by_xpath('//select[@name="ft"]')
    #2.实例化select类
    s= Select(sel)
    #3.选择一个option值 ==通过下标查找
    s.select_by_index(3)
    time.sleep(2)
    #4.通过text
    s.select_by_visible_text('RTF 文件 (.rtf)')
    time.sleep(2)
    #5.通过value
    s.select_by_value('all')
    time.sleep(2)
    # baidu.quit()
  • 相关阅读:
    leetcode 63 简单题
    leetcode 712
    500 问的数学基础
    转载一份kaggle的特征工程:经纬度、特征构造、转化率
    散度
    在线学习在CTR上应用的综述
    广告的计费方式
    矩阵2范数与向量2范数的关系
    text_CNN笔记
    F1
  • 原文地址:https://www.cnblogs.com/wfwt180801-/p/11126702.html
Copyright © 2011-2022 走看看