简体   繁体   English

如何单击随机Web元素?

[英]How can I click random web elements?

I need to automate the page contains several comment entering option fields, for example here is the sample HTML code that page contains with 我需要自动执行包含几个注释输入选项字段的页面,例如,这是页面包含的示例HTML代码

<td id="comment57" class="childhdnshw text-left">
<span id="non_explain_income_0" title=""/>
<div id="explain_income_0_more" class="more ie_7_empty_div"/>
<span id="explain_income_0_text" class="dispno" style="display:none">

First td is dynamic and span id is dynamic and div id is dynamic, I need to enter comment in this page using send keys and I need to select web elements by random how I can do that. 首先, td是动态的, span id是动态的, div id是动态的,我需要使用发送键在此页面中输入评论,我需要随机选择网络元素。

You can find your elements by XPATH, but as your element id is dynamic, try to set your XPATH in a way that handle dynamic ids. 您可以通过XPATH查找元素,但是由于您的元素ID是动态的,请尝试以处理动态ID的方式设置XPATH。 Assuming the dynamic part is _0_ , then this will match: 假设动态部分是_0_ ,那么它将匹配:

driver.find_element_by_xpath('//div[starts-with(@id,"explain_income_")]')

Same way you can match your td and span . 用同样的方法可以匹配tdspan

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在按钮上显示随机活动单击在Android Studio中 - How Can I Display Random Activity On Button Click In Android Studio 如何通过一键单击生成多个随机按钮? - How can I generate multiple random buttons with one button click? 如何将 100 个随机元素添加到具有重复项的空数组中? - How can I add 100 random elements to an empty array with duplicates? 如何单击Web元素中的随机链接 - How to click a random link in a web element 如何在运行时识别和存储所有 web 元素? - How can I identify and store all web elements while runtime? 如何从搜索返回的元素列表中单击随机元素 - How to Click Random element from a list of elements returned by a search 我如何从标记名称为的下拉列表中选择随机元素 <div> ? - How can i select random elements from dropdown lists which has tagname as <div>? 如何在2D数组中填充十个随机元素,而又不填充元素之一? - How can I fill ten random elements in a 2D Array without filling one of the the elements more than once? 当我试图点击android web视图中的元素时,NoSuchElementFoundException - NoSuchElementFoundException when I am trying to click on elements in android web view 我可以在Java中使用listiterator来访问随机位置的元素吗? - Can I use listiterator in Java to access elements in random positions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM