如何在python中使用selenium在html内部#文档中单击按钮?

2024-06-14 08:07:38 发布

您现在位置: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>

如何使用driver.find_element_by单击<td>...</td>内的按钮

我尝试使用chrome复制上面提到的按钮的xpath,并使用driver.find_element_by_xpath运行它,但在将其放入score后没有任何操作

如果有人知道怎么做,请教我


Tags: namesrcwebhtmltablebodymtsframe
1条回答
网友
1楼 · 发布于 2024-06-14 08:07:38

试试这个:

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()

对于帧,您需要打开该帧,然后再切换回帧

相关问题 更多 >