1

I want to use selenium automatically export documents

expect

# -*- 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

This code contains the account and password.Please test use

Automatic login may be incorrect, please try again

Henry Yik
  • 22,275
  • 4
  • 18
  • 40
hakukou
  • 111
  • 1
  • 10

1 Answers1

1

Not found this locator: .find_element_by_id('id-7-export') in the web page, instead you can use 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()
frianH
  • 7,295
  • 6
  • 20
  • 45
  • ```elenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="parts-menu-label" and text()="Export"]"}``` – hakukou Sep 19 '19 at 05:07
  • Not sure you have landing in `test11`, I've changed with this locator: `By xpath` > `//h1[text()="test11"]` – frianH Sep 19 '19 at 05:24
  • hi ``` File "C:/Users/bhhuan/Desktop/20190919/test.py", line 21, in work_on actions = ActionChains(driver) NameError: name 'ActionChains' is not defined ``` – hakukou Sep 19 '19 at 05:52
  • Following impot: `from selenium.webdriver import ActionChains` – frianH Sep 19 '19 at 05:54
  • Welcome, glad it worked, btw my suggest you can use `WebDriverWait` instead `time.sleep(...)`, it will make your project efficient. – frianH Sep 19 '19 at 06:04
  • I have other questions.can you help me, https://stackoverflow.com/questions/58005395/how-to-iterate-button-links-in-selenium – hakukou Sep 19 '19 at 07:07