Issue
Here is the screenshot of the HTML structure for the page I am trying to scrape.
You can see that there is a <table>
element with class="waffle"
. When I use the xpath //table[@class='waffle']
on chrome console, it works as expected:
However when I use the same path on Selenium it doesn't work.
container_xpath = "//table[@class='waffle']"
# wait
try:
wait = WebDriverWait(driver, 30)
container = wait.until(EC.presence_of_element_located((By.XPATH, container_xpath)))
print('container found')
except Exception as e:
print('container not found')
raise PageDidNotLoadError
return
The python script prints "container not found".
What is wrong with selenium?
Solution
<iframe style="border-width: 2px; border-style: solid; border-color: red; width: 1000px; height: 200000px;" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vQT3Q9qDbZUpnP3_WH2I5qw8O-U_PqXVhhoIzH2o-tSzeDND9FTuoGKbZiNHTbrzTgKAUA2_SvXFh_2/pubhtml?gid=159569114&single=true&widget=true&headers=false&gid=0&range=A:F" width="320" height="240"></iframe>
<iframe id="pageswitcher-content" frameborder="0" marginheight="0" marginwidth="0" src="https://docs.google.com/spreadsheets/d/e/2PACX-1vQT3Q9qDbZUpnP3_WH2I5qw8O-U_PqXVhhoIzH2o-tSzeDND9FTuoGKbZiNHTbrzTgKAUA2_SvXFh_2/pubhtml/sheet?headers=false&gid=159569114&range=A:F" style="display: block; width: 100%; height: 100%;"></iframe>
You need to switch to the inner iframe after switching to the outer one.
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#pageswitcher-content")))
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Answered By - Arundeep Chohan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.