简体   繁体   English

如何通过Selenium找到一个由javascript生成的标签(我猜)

[英]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.

相关问题 如何从该表格内容中获取链接(我猜它是 javascript)? (不含硒) - How can I get the link from this table content (I guess it's javascript) ? (Without selenium) 我如何获取JavaScript生成的HTML? - How do i get html produced by javascript? 如何在Javascript中找到h1标签数组的父ID? - How to find the parent id's of an h1 tag array in Javascript? 如何在JavaScript中找到硒元素? - How to find element in JavaScript for selenium? 如何在Selenium的Javascript Web驱动程序中处理警报? - How Can I Handle Alerts In Selenium's Javascript Web Driver? 如何在 Java selenium 中使用 JavascriptExecutor 获得 Javascript 的响应或如何提取<script> tag text? - How do I get response of Javascript using JavascriptExecutor in Java selenium or how to extract <script> tag text? 如何使用JavaScript猜测文件扩展名(客户端) - How to guess file extension with JavaScript (client side) 如何使用javascript或jQuery在标签内使用已知的html内容查找标签的ID? - How do I look for a tag's ID using the known html content inside the tag using javascript or jQuery? 如何使用Javascript删除标签的文本,仅删除文本而不是标签 - How can I remove the tag's text with Javascript, only the text not tag 如何使我的猜测密码代码循环工作? - How can I make my guess-password code's loop work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM