Reputation: 8031
I try to access the following page with Selenium https://view.officeapps.live.com/op/view.aspx?src=https%3A//scholar.harvard.edu/files/torman_personal/files/samplepptx.pptx
While the page is displayed correctly in Firefox/Chrome, elements of the loaded page are not found by Selenium. The code below leads to a "TimeoutException" message as the element PptUpperToolbar.LeftButtonDock.PrintToPdf-Medium20
has not been found.
What do I miss?
# Load ppackages
import urllib.parse
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Define page
file = urllib.parse.quote("https://scholar.harvard.edu/files/torman_personal/files/samplepptx.pptx")
link = "http://view.officeapps.live.com/op/view.aspx?src=" + file
# Setup Webdriver
driver = webdriver.Firefox()
driver.get(link)
# Define wait for "Print to PDF" button to show up
wait = WebDriverWait(driver, 20)
element = wait.until(EC.element_to_be_clickable((By.ID, "PptUpperToolbar.LeftButtonDock.PrintToPdf-Medium20")))
# Check page
# element.get_attribute('outerHTML')
# element.get_attribute('innerHTML')
# Click element
element.click()
Upvotes: 0
Views: 121
Reputation: 12255
The button is inside iframe. You need to switch to the iframe.
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "wacframe")))
wait.until(EC.element_to_be_clickable((By.ID, "PptUpperToolbar.LeftButtonDock.PrintToPdf-Medium20"))).click()
Upvotes: 1