[英]I can't find elements by Id inside html source page Selenium
I am trying to get a list at the website , clicking on a button ('Todas'). 我正在尝试在网站上获取列表,单击一个按钮(“ Todas”)。 The Todas
button Id at the browser html source and my python code are: 浏览器html源上的Todas
按钮ID和我的python代码是:
Button Id:'ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas'
from selenium import webdriver
import time
driver = webdriver.Firefox(executable_path='')
driver.implicitly_wait(12)
driver.get("http://www.bmfbovespa.com.br/pt_br/produtos/listados-a-vista-e-derivativos/renda-variavel/empresas-listadas.htm")
driver.find_element_by_id("ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas")
Error message: 错误信息:
NoSuchElementException: Unable to locate element: {"method":"id","selector":"ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas"} NoSuchElementException:无法找到元素:{“ method”:“ id”,“ selector”:“ ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas”}
In fact, the element is present in the browser html 实际上,元素存在于浏览器html中
I read the related topics but I didn't get a solution. 我阅读了相关主题,但没有找到解决方案。
So, what I need to do in order to click that button and get the data list after? 那么,我需要做些什么才能单击该按钮并在之后获取数据列表?
Thanks so much! 非常感谢!
As I'm seeing in your provided website this TODAS
button is inside an iframe
with id bvmf_iframe
, You need to switch that frame before finding this button as below :- 正如我在您提供的网站中看到的那样,此TODAS
按钮位于ID为bvmf_iframe
的iframe
内,您需要先切换该框架,然后才能找到此按钮,如下所示:-
driver = webdriver.Firefox(executable_path='')
driver.implicitly_wait(12)
driver.switch_to_frame("bvmf_iframe")
driver.get("http://www.bmfbovespa.com.br/pt_br/produtos/listados-a-vista-e-derivativos/renda-variavel/empresas-listadas.htm")
driver.find_element_by_id("ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas")
Reason is because this page is using an iFrame, you will need to swicth to the iframe before attempting to find your element: 原因是因为此页面使用的是iFrame,所以在尝试查找元素之前,您需要先转至iframe:
iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_default_content()
driver.switch_to_frame(iframe)
driver.find_element_by_id("ctl00_contentPlaceHolderConteudo_BuscaNomeEmpresa1_btnTodas")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.