Sumit Banerjee
Sumit Banerjee

Reputation: 1

Unable to click an element within iframe in IE

I want to click on an element as follows:

//select[@name='instructionSelection']

But its not clicking with Selenium on IE 11.

HTML:

enter image description here

Upvotes: 0

Views: 141

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193088

As the the desired element is within an <iframe> so to invoke click() on the element you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following Locator Strategies::

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='invoiceDeatils'][src*='invoiceDeatils']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select[name='instructionSelection']"))).click()
      
    • Using XPATH:

      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='invoiceDeatils' and contains(@src, 'invoiceDeatils')]")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@name='instructionSelection']"))).click()
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

Reference

You can find a relevant discussion in:

Upvotes: 0

supputuri
supputuri

Reputation: 14135

You have to switch to iframe using name=InvoiceDeatils before interacting with the element.

Not sure which language you are using. Providing the snippet in python below.

driver.switch_to.frame(driver.find_element_by_name('InvoiceDeatils'))
# now click on the element
driver.find_element_by_xpath("//select[@name='instructionSelection']").click()

Upvotes: 1

Related Questions