How to click a link from a frame using Selenium Webdriver?

Asked

Viewed 1,633 times

1

I’m studying a book Automate Massive Tasks with Python. I’m on page 317 that talks about Selenium Webdriver on the methods of finding elements on the pages.

Table 11.3 - Selenium’s Webdriver methods for finding elements. After making this small example below I stopped/impaled when clicking on the Wireles link on the left side of the page. Because I noticed that the link is part of a frame and the same "is not found" on 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()

inserir a descrição da imagem aqui

1 answer

0


You can use the switch_to_frame of driver to change the context to the 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 I switched to frame successfully, you can search for the elements you want:

driver.switch_to_frame("frame").find_element_by_id("menu_wl").click();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.