[英]How to find by Selenium a tag that's produced by javascript (I guess)
Heyo! Heyo!
I have to download a file from corporate site by using Selenium, and got stucked on the last step: 我必须使用Selenium从公司站点下载文件,并且最后一步陷入困境:
When I press Ctrl+U on the site the code contains only base tags like and some s those are empty: 当我在网站上按Ctrl + U时,代码只包含基本标签,有些是空的:
<div ng-show="viewContainer === 'PUC'"
class="ng-app-element deny-animation-change" animate="fade"
id="pucWrapper" cellspacing="0" cellpadding="0" style="width: 100%; height: 100%;">
<div id="pucHeader" cellspacing="0" cellpadding="0">
<div id="pucMenuBar"></div>
<div id="pucPerspectives"></div>
<div id="pucToolBar"></div>
<div id="pucUserDropDown"></div>
</div>
<div id="pucContent"></div>
</div>
but when i select and inspect an element by Chrome dev tool it says that there are many tags in <div id="pucContent">
, how to find an "invisible" <select>
tag by Selenium? 但是当我通过Chrome开发工具选择并检查一个元素时,它说
<div id="pucContent">
中有很多标签,如何通过Selenium找到“隐形” <select>
标签?
The code below returns with NoSuchElementException
下面的代码返回
NoSuchElementException
WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.ID, 'pucContent'))).find_element_by_tag_name('select')
My guess that javascript creates new tags and all content within <div id="pucContent">
tag 我猜javascript会在
<div id="pucContent">
标签内创建新标签和所有内容
My guess is that <div id="pucContent"></div>
is there at the beginning and gets populated after the page is loaded. 我的猜测是
<div id="pucContent"></div>
在开头就有,并在页面加载后填充。 So what you really need to be waiting for in your wait is something inside that. 所以你在等待中真正需要等待的是内在的东西。 If there is a
<select>
inside that elemeint when you inspect, try waiting like this: 如果检查时elemeint中有
<select>
,请尝试这样等待:
WebDriverWait(browser, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '#pucContent select'))).find_element_by_tag_name('select')
Keep in mind the "page_source" of a web page is only what is passed when the document is requested, it won't contain anything loaded dynamically after the original document is loaded. 请记住,网页的“page_source”只是在请求文档时传递的内容,它不包含在加载原始文档后动态加载的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.