硒点击非按钮元素 [英] Selenium Click on non button element

查看:120
本文介绍了硒点击非按钮元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是代码:

  driver.navigate()。(https://www.facebook.com/DavidGuetta/posts/10153196593446356); 
driver.findElement(By.xpath(// a [contains(。,'Like')]))。click();

但不幸的是它不工作..
我也试过这个

  WebDriverWait wait = new WebDriverWait(driver,10); 

wait.until(ExpectedConditions.elementToBeClickable(By.xpath(// a [contains(。,'Like')])))。

没有运气,只是不知道为什么按钮没有点击,请帮助..谢谢:)

解决方案

您可以尝试下面的cssSelector。它在我的机器上工作。

 通过locator = By.cssSelector(a [data-testid ='fb-ufi-likelink ]); 
driver.findElement(locator).click();

如果不起作用请给我异常信息。


I Want to click on a Facebook Post Like button using Selenium and Java With no Luck .

Here is the code:

driver.navigate().to("https://www.facebook.com/DavidGuetta/posts/10153196593446356");
driver.findElement(By.xpath("//a[contains(.,'Like')]")).click();

But sadly it does not work .. i've tried this too

WebDriverWait wait = new WebDriverWait(driver, 10);

    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(.,'Like')]"))).click();

with no luck , just do not know why the button is not clicked , please help .. and thanks :)

解决方案

You can try cssSelector below. It works on my machine.

By locator = By.cssSelector("a[data-testid='fb-ufi-likelink']");
driver.findElement(locator).click();

If it doesn't work. Please give me the exception message.

这篇关于硒点击非按钮元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆