我想在span标记内点击使用id属性的链接,不知道点击链接是否有帮助。
以下是两个不同的HTML代码示例
1
<span class="handIcon" title="Click Task" id="hand_175931762" campaignid="799214" link="https://www.facebook.com/profile.php?id=100006050206969" onclick="updateTask(175931762, this)"><i class="fa fa-hand-o-up custom"></i></span>
2
<span id="hand_175931760" campaignid="802712" link="https://www.facebook.com/Majumder-Enterprise-154524208363753/"><i class="fa fa-hand-o-up custom"></i></span>
其中handIcon是链接图像。
1。id="hand_175931762"
与2。id="hand_175931760"
HTML代码不同。
我想点击的链接会动态变化,当点击一个链接时等待30秒,之后下一个链接处于活动状态,然后再等待30秒,继续。
我正在使用此代码
driver.findElement(By.xpath("//*[contains(text(),'hand')]")).click();,
但它引发了我错误
org.openqa.selenium:ElementNotVisibleException
提前致谢
答案 0 :(得分:0)
id
属性的值不是text()
,因此您的元素无法与"//*[contains(text(),'hand')]"
匹配。仅当您的元素看起来像<span>hand_175931762</span>
请尝试以下方式:
driver.findElement(By.xpath("//span[starts-with(@id, 'hand_')]")).click();
答案 1 :(得分:0)
代码有效,因为它没有给出任何错误,但链接没有被点击,因为链接的ID已经更改,因为已经点击了具有此ID <span>hand_175931762</span>
的链接。没有更长的活动链接。
<span>hand_175931762</span>
到
<span class="handIcon" title="Click Task" id="hand_175931753" campaignid="797945" link="www.SAP.in" onclick="updateTask(175931753, this)"><i class="fa fa-hand-o-up custom"></i></span>
那
谢谢@Andersson