简体   繁体   中英

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

<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.

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. Assuming the dynamic part is _0_ , then this will match:

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

Same way you can match your td and span .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM