Selenium find_element_by_xpath不适用于SharePoint 2013

时间:2016-05-06 09:48:24

标签: python selenium

我想配置Selenium以打开SharePoint 2013列表并下载它(导出到excel)。我可以在列表中单击selenium以显示导出到Excel的选项,但是当我使用xpath单击导出到Excel时,我得到一个错误,说它找不到xpath。知道为什么吗?

按钮的Html代码是:

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

Xpath是:

//*[@id="Ribbon.List.Actions.ExportToSpreadsheet-Medium"]/span[2]

下面的代码和打印。

感谢。

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'
browser.get(url)

time.sleep(2)

browser.find_element_by_xpath("//*[@id='Ribbon.List-title']/a/span[1]").click()

time.sleep(4)


browser.find_element_by_xpath("//*[@id='Ribbon.List.Actions.ExportToSpreadsheet-Medium']/span[2]").click()

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试下面的代码并告诉我它是否无法正常工作:

xpath = '//span[@class="ms-cui-ctl-largelabel"][contains(text(), "Export to")]'
browser.find_element_by_xpath(xpath).click()