簡體   English   中英

如何選擇二級隱藏菜單

[英]How to choose a secondary hidden menu

我想用selenium自動導出文件

預計

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
import time

# Configuration information
email = "my_email"
password = "my_password"



def work_on():
    driver = webdriver.Chrome()
    index_url = "https://quip.com/"
    driver.get(url=index_url)
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="header-nav-collapse"]/ul/li[9]/a').click()  # click login
    time.sleep(1)
    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/form/div/input').send_keys(email)  # input email
    driver.find_element_by_xpath('//*[@id="email-submit"]').click()
    time.sleep(1)
    driver.find_element_by_xpath('/html/body/div/div/form/div/input[2]').send_keys(password)  # input password
    driver.find_element_by_xpath('/html/body/div/div/form/button').click()
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[1]/div/div/div[3]/div[1]/a[2]/div/div').click()  # click file
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[3]/div[2]/div/div/div/div[1]/div[2]/div[1]/a').click()  # select test
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[3]/div[2]/div/div/div/div/div[2]/div/a').click()  # select test
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[3]/div[1]/div[1]/div[1]/div[2]/button[1]').click()  # select document
    time.sleep(2)
    ele = driver.find_element_by_id('id-7-export')  # Determine the position of the element
    actions = ActionChains(driver)
    actions.move_to_element(ele)
    actions.click(ele) # Export to html
    actions.perform()

    time.sleep(5)
    driver.close()


if __name__ == '__main__':
    work_on()

錯誤信息

ele = driver.find_element_by_id('id-7-export')  # Determine the position of the element

找不到 label 無法導出

此代碼包含賬號和密碼,請測試使用

自動登錄可能不正確,請重試

在 web 頁面中未找到此定位器: .find_element_by_id('id-7-export') ,您可以使用xpath

//div[@class="parts-menu-label" and text()="Export"] -> to export
//div[@class="parts-menu-label" and text()="HTML"] -> to HTML

試試下面的:

def work_on():
    driver = webdriver.Chrome()
    index_url = "https://quip.com/"
    driver.get(url=index_url)
    time.sleep(1)
    driver.find_element_by_xpath('//*[@id="header-nav-collapse"]/ul/li[9]/a').click()  # click login
    time.sleep(1)
    driver.find_element_by_xpath('/html/body/div[2]/div[1]/div[1]/form/div/input').send_keys(email)  # input email
    driver.find_element_by_xpath('//*[@id="email-submit"]').click()
    time.sleep(1)
    driver.find_element_by_xpath('/html/body/div/div/form/div/input[2]').send_keys(password)  # input password
    driver.find_element_by_xpath('/html/body/div/div/form/button').click()
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[1]/div/div/div[3]/div[1]/a[2]/div/div').click()  # click file
    time.sleep(5)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[3]/div[2]/div/div/div/div[1]/div[2]/div[1]/a').click()  # select test
    time.sleep(2)
    driver.find_element_by_xpath('//h1[text()="test11"]').click()  # select test
    time.sleep(2)
    driver.find_element_by_xpath('//*[@id="app"]/div/div/div/div[3]/div[1]/div[1]/div[1]/div[2]/button[1]').click()  # select document
    time.sleep(2)
    ele = driver.find_element_by_xpath('//div[@class="parts-menu-label" and text()="Export"]')  # Determine the position of the element
    actions = ActionChains(driver)
    actions.move_to_element(ele).perform()
    time.sleep(1)
    html = driver.find_element_by_xpath('//div[@class="parts-menu-label" and text()="HTML"]')
    actions.move_to_element(html).click(html).perform()

    time.sleep(5)
    driver.close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM