使用xpath无法让selenium为我选择一个按钮。我错过了什么?

时间:2014-02-21 18:44:41

标签: java python selenium xpath

continue_button = browser.find_element_by_xpath("//input[@type='button' and @class='primary button']")
continue_button.click();

由于某种原因,这不起作用。这就是我所知道的点击按钮: 它在一个div AND

<button class="primary button" type="button"></button>

这就是我必须要做的一切。救命? browser.find_element_by_id适用于同一页面上的其他项目,因此我的驱动程序和一切正常。

它加载页面,在文本中键入我已设置的字段,我希望它单击“继续”按钮,它只是停止和结束。

原始html:

<div class="GLHWMP-BMTC">

<span class="inlineBlock GLHWMP-BDUC">
    <button class="primary button" type="button"></button>
    <span class="GLHWMP-BPTC GLHWMP-BEUC"></span>
    <span class="GLHWMP-BPTC GLHWMP-BLTC"></span>
</span>

1 个答案:

答案 0 :(得分:3)

您尝试点击的元素类型为<button>

首先,您需要将//input更改为//button

此外,您不必同时使用class属性和type属性,除非这是唯一标识该元素的唯一组合。否则,您可以只使用唯一标识元素的属性(class属性或type属性)。