如何点击一个动态变化的 link (Selenium Webdriver)

How to click on a dynamic changing link (Selenium Webdriver)

我想点击一个 link using id 属性 inside span tag ,不知道点击 link.

是否有帮助

这里有两个不同的例子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 是 Link 图片。

在 1.id="hand_175931762" 不同于 2.id="hand_175931760" HTML 代码.

它们是我想要单击的动态变化的 links,单击一个 link 时需要等待 30 秒,之后是下一个 link激活,然后再等待 30 秒,继续。

我正在使用此代码

driver.findElement(By.xpath("//*[contains(text(),'hand')]")).click();,

但它抛出错误

org.openqa.selenium:ElementNotVisibleException

提前致谢

id 属性的值不是 text(),因此您的元素无法与 "//*[contains(text(),'hand')]" 匹配。仅当您的元素看起来像 <span>hand_175931762</span>

时才可以应用此方法

请尝试以下操作:

driver.findElement(By.xpath("//span[starts-with(@id, 'hand_')]")).click();

代码有效,因为它没有给出任何错误,但是 link 没有被点击,因为 link 的 ID 已经改变,因为 link 有这个 ID <span>hand_175931762</span> 已被点击。不再有效 link。

<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