Unable to access Pop Up / iframe window using selenium python
I am using chromedriver version 100. Your code throws a NoSuchElementException
. Thats because your driver tries to find an element which does not exist. So, what you need to do is to put time.sleep(4)
statements after your click()
statements (Your browser needs time to open the window/s). If you are done using the driver, use driver.quit()
.
Followed code worked for me:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome('C:/Users/hamhatre/Desktop/chromedriver.exe')
driver.get("https://shopatsc.com/collections/playstation-5/products/ps5-horizon-forbidden-west")
driver.maximize_window()
driver.implicitly_wait(20)
elem = driver.find_element_by_xpath('//*[@id="pincode_input"]')
elem.send_keys("400708")
driver.find_element_by_xpath('//*[@id="check-delivery-submit"]').click()
driver.find_element_by_xpath('/html/body/div[2]/main/div[1]/div/div/div/div[2]/div[1]/form/div[3]/div/button[2]').click()
driver.find_element_by_xpath('//*[@id="checkout_email"]').send_keys('abc@gmail.com')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_first_name"]').send_keys('abc')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_last_name"]').send_keys('xyz')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_address1"]').send_keys('Rd1, Flat no 2, Apt 1')
driver.find_element_by_xpath(('//*[@id="checkout_shipping_address_address2"]')).send_keys('Nothing')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_city"]').send_keys('Mumbai')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_province"]').send_keys('Maharashtra')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_zip"]').send_keys('400708')
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_phone_custom"]').send_keys('9876543210')
driver.find_element_by_id('continue_to_shipping_button_custom').click()
time.sleep(4)
driver.find_element_by_id('continue_button').click()
time.sleep(4)
driver.find_element_by_xpath('/html/body/div/div/div/main/div[1]/div/form/div[3]/div[1]/button').click()
time.sleep(4)
print(driver.title)
seq = driver.find_elements_by_tag_name('iframe')
print(seq)
print("No of frames present in the web page are: ", len(seq))
for index in range(len(seq)):
iframe = driver.find_elements_by_tag_name('iframe')[index]
driver.switch_to.frame(iframe)
driver.find_element_by_id('language-dropdown').click()
Selenium - Unable to find input elements inside iframe using SwitchTo()
wait=WebDriverWait(driver,10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"#tab1")))
You are using Java use Python instead and waits.
driver.SwitchTo().Frame(driver.FindElement(By.id("tab1")));
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Unable to find element in iframes using Selenium WebDriver Python
The load chart layout
is present inside nested iframes
.
To handle dynamic element
Induce WebDriverWait
() and frame_to_be_available_and_switch_to_it
() following css
selector
Induce WebDriverWait
() and wait for element_to_be_clickable
() and following css
selector
driver.find_element_by_xpath("/html/body/div[5]/section/div[4]/div[1]/a").click()
print("live charts clicked")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='tvc_frame']")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src$='GB']")))
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='tradingview']")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.save-load-buttons>span.load"))).click()
print("successfully clicked load")
You need to import following libraries
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Selenium Webdriver (Python) - Unable to locate element inside nested iframes
The element is inside multiple <iframe>
tags, you need to switch to them one by one. You should also maximize the window and use explicit wait as it take some time to load
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chrome_path = r"C:\Users\gh455\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.maximize_window()
driver.get("https://www.nissanoflithiasprings.com/schedule-service")
wait = WebDriverWait(driver, 10)
# first frame - by css selector
wait.until(ec.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, '[src^="https://consumer.xtime.com"]')))
# second frame - by ID
wait.until(ec.frame_to_be_available_and_switch_to_it('xt01'))
driver.find_element_by_id("new_customer_button")
Related Topics
Can You Access UI Elements from Another Thread? (Get Not Set)
System.Io.Filestream Fileaccess VS Fileshare
Cookie Authentication Expiring Too Soon in ASP.NET Core
Getting Relative Virtual Path from Physical Path
Adding Multiple Icons (Win32-Resource) to .Net-Application
How to Write a Comment to an Xml File When Using the Xmlserializer
How to Set a Proxy for Webbrowser Control Without Effecting the System/Ie Proxy
How to Find Duplicates in an Array and Display How Many Times They Occurred
Why am I Getting 'One or More Types Required to Compile a Dynamic Expression Cannot Be Found.'
Multiple Controller Types with Same Route Prefix ASP.NET Web API
Split String into Smaller Strings by Length Variable
Linq to Xml - Update/Alter the Nodes of an Xml Document
How to Use Dependency Injection in a .Net Core Actionfilterattribute