• python-selenium-粘贴,删除,复制和悬停


    from selenium import webdriver

    from selenium.webdriver.common.keys import Keys
    import time

    访问谷歌浏览器

    driver=webdriver.Chrome()

    访问地址

    driver.get("")

    最大窗口

    driver.maximize_window()

    time.sleep(1)

    输入文字

    ele=driver.find_element_by_xpath('//*[@id="kw"]')
    ele.send_keys("英雄联盟")

    ele.send_keys(Keys.BACKSPACE)

    time.sleep(1)

    全选

    ele.send_keys(Keys.CONTROL,'a')
    time.sleep(1)

    剪切

    ele.send_keys(Keys.CONTROL,'x')
    time.sleep(1)

    粘贴

    ele.send_keys(Keys.CONTROL,'v')

    悬停

    from selenium import webdriver

    悬停要用的包

    from selenium.webdriver import ActionChains

    import time
    # 创建浏览器
    driver = webdriver.Chrome()

    调整浏览器尺寸

    driver.maximize_window()

    # 访问链接
    driver.get("https://study.163.com/")
    driver.find_element_by_xpath('//*[@id="ux-modal"]/div[3]/span').click()
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="j-pclose"]').click()
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="ux-modal"]/div[1]/a').click()
    time.sleep(1)

    悬停用法

    ActionChains(driver).move_to_element(driver.find_element_by_xpath('//span[@class="arrow down ux-icon-caret-down"]')).perform()
    # time.sleep(1)
    ActionChains(driver).move_to_element(driver.find_element_by_xpath('(//a)[@title="生活兴趣"][2]')).perform()
    # time.sleep(1)
    driver.find_element_by_xpath('(//a)[@title="手工DIY"][2]').click()
    # 保存快照
    driver.save_screenshot("1.png")

  • 相关阅读:
    oracle增加类似sqlserver中的timestamp字段
    开源项目微人事
    java.lang.IllegalStateException: Form too many keys
    java.lang.IllegalStateException: Form too large 59992>50000
    axios.CancelToken
    节流 防抖重温
    c语言中%d %f %c %s等的区别
    C语言当中int,float,double,char这四个有什么区别?
    openssl windows 编译
    python不同版本pip下载模块方法
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13309155.html
Copyright © 2020-2023  润新知