Gonzalo Gonzalo - 1 year ago 174
Python Question

Selenium find_element_by_xpath not working for SharePoint 2013

I would like to configure Selenium to open a SharePoint 2013 list and download it (export to excel). I can have selenium clicking in the List to show the option to Export to Excel, but when I use the xpath to click in Export to Excel I get an error sayng it doesnt find the xpath. Any idea why?

Html code of the button is:

<span unselectable="on" class="ms-cui-ctl-largelabel">Export to<br>Excel</span>

Xpath is:


Code and Print below.


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

path_to_Ie = 'C:\\Python34\\IEDriver\\IEDriverServer.exe' # change path as needed
browser = webdriver.Ie(executable_path = path_to_Ie)
url = 'https://group.shareplace.test/sites/site2/Lists/Actions/AllItems.aspx'





enter image description here

Answer Source

Try below code and let me know if it's not working properly:

xpath = '//span[@class="ms-cui-ctl-largelabel"][contains(text(), "Export to")]'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download