switch to Iframe with selenium
Question:
How do i switch to a iframe with selenium, i’m trying to scrap data, but today the website updated and add a iframe. Now i didnt know how to switch and enter in the iframe to collect the data.
thats the iframe =
<iframe _ngcontent-xyi-c154="" type="text/html" frameborder="0" width="100%" scrolling="auto" src="https://direct.argusmedia.com/integration/price/pricedata" style="height: 2808px;"></iframe>
Answers:
You must use an XPath to locate the iframe element first
iframe = driver.find_element(By.XPATH,"//iframe[@src='https://direct.argusmedia.com/integration/price/pricedata']")
Then switch_to the iframe
driver.switch_to.frame(iframe)
To switch back to the Parent Frame you can use the following line of code:
driver.switch_to.parent_frame()
To switch back to the Top Level Browsing Context / Top Window you can use the following line of code:
driver.switch_to.default_content()
//Wait for frame
can you try adding a wait for frame
wait = WebDriverWait(driver, 30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//iframe[@src='https://direct.argusmedia.com/integration/price/pricedata']')))
How do i switch to a iframe with selenium, i’m trying to scrap data, but today the website updated and add a iframe. Now i didnt know how to switch and enter in the iframe to collect the data.
thats the iframe =
<iframe _ngcontent-xyi-c154="" type="text/html" frameborder="0" width="100%" scrolling="auto" src="https://direct.argusmedia.com/integration/price/pricedata" style="height: 2808px;"></iframe>
You must use an XPath to locate the iframe element first
iframe = driver.find_element(By.XPATH,"//iframe[@src='https://direct.argusmedia.com/integration/price/pricedata']")
Then switch_to the iframe
driver.switch_to.frame(iframe)
To switch back to the Parent Frame you can use the following line of code:
driver.switch_to.parent_frame()
To switch back to the Top Level Browsing Context / Top Window you can use the following line of code:
driver.switch_to.default_content()
//Wait for frame
can you try adding a wait for frame
wait = WebDriverWait(driver, 30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//iframe[@src='https://direct.argusmedia.com/integration/price/pricedata']')))