单击selenium python中悬停的活动按钮

2024-06-16 14:24:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想点击“确定”按钮。按钮的HTML如下所示:

**<span class="button-group">
<span id="yui-gen159" class="yui-button yui-push-button alf-primary-button">
<span class="first-child">
<button type="button" id="yui-gen159-button">OK</button>
</span>
</span>
<span id="yui-gen160" class="yui-button yui-push-button default">
<span class="first-child">
<button type="button" id="yui-gen160-button">Cancel</button>
</span>
</span>
</span>**

单击“确定”按钮的python代码是:

def hover(self):

        element = driver.find_element_by_link_text("OK")

        hov = ActionChains(driver).move_to_element(element)

        hov.perform()

        WebDriverWait.until(EC.element_to_be_clickable((By.link_text, "OK"))).click()

使用此代码,我的“OK”按钮会高亮显示,但不会被单击。我也尝试了很多其他的方法,但都无法使用


Tags: 代码idchildtypebuttonokelement按钮