我正在尝试点击并使用selenium webdriver标记按钮的“添加课程”,但它不适合我。
这是我从chrome开发人员工具中获取的代码片段:
<button type="button" class="btn btn-green" onclick="javascript:AddCourse();">
<span class="glyphicon glyphicon-plus-sign">
::before
</span>
<span translate="portallang_addCourse" class="open-sans ng-scope">
"Add Course"
</span>
</button>
您需要以下xpath之一:
第一选择:
//span[contains(text(), 'Add Course')]
这两个,只有总共有2个跨度而第二个跨度总是添加课程:
(//button[@class='btn btn-green']/span)[2]
//button[@class='btn btn-green']/span[2]
扫描整个文档时选项最慢。添加课程只能在页面上出现一次:
//*[contains(text(), 'Add Course')]
你遇到了什么错误?您使用什么属性来单击span元素?
你必须使用xpath来表示这些元素。
使用Chrome的xPath Finder插件并提取此元素的唯一xpath:https://chrome.google.com/webstore/detail/xpath-helper/hgimnogjllphhhkhlmebbmlgjoejdpjl?hl=en
您始终可以手动编写唯一的xpath,但这样可以节省时间并且准确无误。
希望这可以帮助!