Home > database >  Selenium - Unable to find input elements inside iframe using SwitchTo()
Selenium - Unable to find input elements inside iframe using SwitchTo()

Time:01-29

I have a hard time locating two input elements of a specific website.

website

Well, as you can see above, "username" input element and "password" input element are inside an iframe with id = tab1.

So I tried (among other things) something like this:

driver = webdriver.Firefox()

driver.get('https://www.website.com/sites/en/Pages/default.aspx')

driver.SwitchTo().Frame(driver.FindElement(By.id("tab1")));

username = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="login-form"]/div[1]/input')))
username.send_keys(credentials.username)

password = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="login-form"]/div[2]/input')))
password.send_keys(credentials.password)

submit = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="loginBtn"]')))

action = ActionChains(driver)
action.move_to_element(submit).click().perform()

That is, I switched to frame "tab1" and then searched for the elements with their XPath. (Both full XPath and simple XPath).

But I get the following error again and again:

Process finished with exit code -1073740791 (0xC0000409)

without even activating "try-except" to show me something I can use for debugging.

Well, the question is: can I locate these elements somehow?

Thank you in advance.

CodePudding user response:

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
  •  Tags:  
  • Related