How to click on a link in a frame using Selenium WebDriver?

1

I'm studying a book Automating Massive Tasks with Python. I'm on page 317 that talks about Selenium WebDriver about methods of finding elements on pages.

Table 11.3 - The Selenium WebDriver methods for finding elements. After doing this little example below I stopped / I stuck at the time of clicking the Wireles link on the left side of the page. Well I noticed that the link is part of a frame and the same "is not found" in the current page. Wireless Router N 300Mbps WR840N model TL-WR840N .

#Importando selenium
from selenium import webdriver
#Importando as teclas especiais {ENTER}{TAB}{DOWN}...
from selenium.webdriver.common.keys import Keys
#Escolhendo o browser padrao
browser=webdriver.Chrome()
#abrindo o endereco do roteador
browser.get('http://192.168.100.1')
#maximizando a janela atual
browser.maximize_window()
#Digitando o usuario
browser.find_element_by_id('userName').send_keys('admin')
#Digitando a senha
browser.find_element_by_id('pcPassword').send_keys('admin')
#Clicando no botao Login
browser.find_element_by_id('loginBtn').click()

    
asked by anonymous 14.06.2018 / 08:04

1 answer

0

You can use the driver to change the context to frame :

// usando o nome da frame
driver.switch_to_frame(["nome da frame"])

// usando um localizador (vulgo find_element_by)
driver.switch_to_frame(driver.find_element_by_?)

After successfully switching to frame , you can search for the elements you want:

driver.switch_to_frame("frame").find_element_by_id("menu_wl").click();
    
14.06.2018 / 09:31