Reputation: 305
I need to click on two buttons located in the top command bar in a SharePoint list to complete a CSV download.
I have attempted using the 2 locators below and a explicit wait below with no success.
driver.find_element_by_xpath('//*[@id="appRoot"]/div[1]/div[3]/div/div[2]/div[2]/div[2]/div[1]/div/div/div/div/div/div/div[1]/div[4]/button/span').click()
driver.find_element_by_xpath('//*[@id="id__850-menu"]/div/ul/li[2]/button/div/span').click()
excel_btn = (By.ID, 'id__124-menu')
csv_btn = (By.ID, 'ContextualMenu427')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(excel_btn)).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(csv_btn)).click()
Export button html:
<span class="ms-Button-flexContainer flexContainer-124" data-automationid="splitbuttonprimary"><i data-icon-name="svg/excel_16x1_5.svg" aria-hidden="true" class="ms-Button-icon icon-127"><img alt="" src="https://spoprod-a.akamaihd.net/files/fabric-cdn-prod_20201207.001//assets/brand-icons/product/svg/excel_16x1_5.svg"></i><span class="ms-Button-textContainer textContainer-119"><span class="ms-Button-label label-125" id="id__850">Export</span></span><i data-icon-name="ChevronDown" role="presentation" aria-hidden="true" class="ms-Icon root-33 css-81 ms-Button-menuIcon is-expanded menuIcon-187" style="font-family: FabricMDL2Icons;"></i><span class="ms-layer"></span></span>
CSV button html:
<div class="ms-ContextualMenu-linkContent linkContent-199"><span class="ms-ContextualMenu-itemText label-205">CSV</span></div
Error:
Traceback (most recent call last):
File "C:\Users\main.py", line 44, in <module>
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(excel_btn)).click()
File "C:\Users\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
My code:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pandas
from tkinter import messagebox
driver = webdriver.Chrome(r"C:\Users\chromedriver.exe") # change path
target_url = 'some_url'
driver.get(target_url)
email_field = (By.ID, "i0116")
password_field = (By.ID, "i0118")
next_btn = (By.ID, "idSIButton9")
two_factor_btn = (By.ID, 'idSubmit_SAOTCC_Continue')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(email_field)).send_keys("username")
# Click Next
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(next_btn)).click()
# wait for password field and enter password
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(password_field)).send_keys("password")
# Click Login
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(next_btn)).click()
# shows message box to promp input
messagebox.showinfo(title='2-step verification', message='Input on 2-step verification, (30 seconds timeout)')
time.sleep(30)
# 2 factor auth
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(two_factor_btn)).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(next_btn)).click()
# download csv
excel_btn = (By.ID, 'id__124-menu')
csv_btn = (By.ID, 'ContextualMenu427')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(excel_btn)).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(csv_btn)).click()
# driver.find_element_by_xpath('//*[@id="id__124-menu"]/div/ul/li[1]/button/div')
# driver.find_element_by_xpath('//*[@id="ContextualMenu427"]/div/ul/li[2]/button/div/span')
Thanks for your help!
Upvotes: 1
Views: 1002
Reputation: 33384
I don't find any such ID
the HTML you have provided. Try with following xpath.
excel_btn = (By.XPATH, "//span[text()='Export']")
csv_btn = (By.XPATH, "//Span[text()='CSV']")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(excel_btn)).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(csv_btn)).click()
Hope this will resolved your problem.
Upvotes: 1