简体   繁体   English

如何选择二级隐藏菜单

[英]How to choose a secondary hidden menu

I want to use selenium automatically export documents我想用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()

Error message错误信息

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

Cannot find label can't be exported找不到 label 无法导出

This code contains the account and password.Please test use此代码包含账号和密码,请测试使用

Automatic login may be incorrect, please try again自动登录可能不正确,请重试

Not found this locator: .find_element_by_id('id-7-export') in the web page, instead you can use xpath :在 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

Try the bellow:试试下面的:

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.

相关问题 如何在词典菜单中选择单词? - How to choose the word in the dictionary menu? 仪表板上的Django隐藏菜单 - Django Hidden menu on dashboard 如何通过更新菜单更新 Plotly 图表的次 Y 轴 - How can one update the secondary Y-axis of a Plotly chart through an update menu 如何单击使用 Selenium 隐藏的下拉菜单? - How do I click on a drop down menu that is hidden using Selenium? 如何为 tf.keras 模型的隐藏层选择输出神经元的值? - How can I choose the value of output neurons for the hidden layer of tf.keras model? 熊猫:按第一个索引的范围在MultiIndex上切片,然后选择第二个索引标签 - pandas: slice on MultiIndex by range of first index, and choose secondary index label 如何使用打印语句创建菜单? 我希望能够选择一个数字,并根据我选择的数字运行该功能 - How do i create a menu using print statements? I want to be able to choose a number and based on what number i choose run that function 使用 selenium 单击二级菜单中的下拉菜单 - Using selenium to click a dropdown menu within a secondary menu 为什么网页中的下拉菜单被隐藏 - Why is Dropdown Menu in Webpage Hidden 如何在代码开头添加菜单以选择用户想要在 Python 中使用的代码部分? - How can I add a menu at the start of a code to choose which part of code the use wants to use in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM