-2

I am trying this code to click on the javascript button. In the first frame you find the content, but when I place myself in the second html there is no menu.

How do I click on the button?

enter image description here

Code trials:

driver.switch_to.default_content()
driver.find_element_by_tag_name('frameset')
driver.switch_to_frame(1)
driver.find_element_by_tag_name('html')

print(driver.page_source)

driver.find_element_by_tag_name('frameset')
driver.switch_to_frame(1)
driver.find_element_by_tag_name('html')    

print(driver.page_source)

<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    
    </head><frameset cols="170px,100%" framespacing="0" border="0" frameborder="0">
                    <frame scrolling="no" name="menu" id="menu" src="menu.jsp" />
                    <frame scrolling="yes" name="main" id="main" src="main.jsp" />
    </frameset>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Lafayette
  • 43
  • 3
  • 2
    Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Jul 20 '19 at 23:00

1 Answers1

0

As the the desired element is within an multiple <iframe>s so you have to:

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

    • Code Block:

      from selenium import webdriver
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      from selenium.webdriver.common.by import By
      
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[contains(@src, 'login')]")))
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[@id='menu' and @name='menu'][contains(@src, 'menu')]")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "squeda Avanzada"))).click()
      

Here you can find a relevant discussion on Ways to deal with #document under iframe

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Your locators are terrible and as I've mentioned before, the Selenium contributors have advised multiple times to avoid XPath when possible. Neither of your first two locators need to be XPath and for the second, there's no reason to use anything but `*_by_id('menu')`. It's simpler, better supported and there's nothing in the HTML to indicate that it won't work. – JeffC Jul 20 '19 at 22:59