简体   繁体   中英

How to click button inside html inside #document using selenium in python?

<html>
<frame src="/mts.web/Menu_big5.aspx" name="leftFrame2" scrolling="no" noresize="">
    #document
        <!doctype html PUBLIC "-//W3C//DTD MTML 4.01 Transtitional//EN">
        <html>
           <Head></Head>
           <Body>
                <table>
                     <tbody>
                          <tr>
                             <td>
                                <a href="javascript:inputOrder('B')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image2','','images/btn/buy_on_b5.gif',1)">
                                <img src="https://bss2.bsgroup.com.hk/mts.web/images/btn/buy_b5.gif" name="Image2" width="92" height="20" border="0">
                                </a>
                             </td>
                          </tr>
                     </tbody>
                </table>
           </Body>
        </html>   
</frame>
</html>

How do I use driver.find_element_by to click the button inside <td>...</td>

I tried to copy the xpath of the button I said above using chrome and run it using driver.find_element_by_xpath but no action after I put it in score.

Please if someone know how to do it, teach me please.

Try This:

driver.switch_to.frame(driver.find_element_by_name("leftFrame2"))
#Now Execute Your code Here
#After that add this line
driver.switch_to.default_content()

for frame you need to switch on that and then switch back

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