Selenium和Facebook Post按钮:如何使用Selenium在Java中单击Facebook Post按钮? [英] Selenium and Facebook Post Button: How to click facebook post button in java using selenium?

查看:43
本文介绍了Selenium和Facebook Post按钮:如何使用Selenium在Java中单击Facebook Post按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

driver.get("https://www.facebook.com/sachin.aryal");
driver.findElement(By.name("xhpc_message_text")).sendKeys("Testing Java and Selenium");
driver.findElement(By.xpath("//*[@id='u_0_1a']/div/div[6]/div/ul/li[2]/button")).click();

代码的最后一行不起作用.如何在Facebook上设置发布"按钮的XPath?

The last line of the code is not working. How do I set the XPath of the Post button on facebook?

推荐答案

我知道您已经标记了自己的答案,但这不是正确的方法.Selenium内置了多种方法来进行等待,例如等待元素可点击.这种方法是执行此操作的正确且更有效的方法.

I know you already marked your own answer but it's not the proper way to do this. There are ways built into Selenium to do waits, e.g. wait for an element to be clickable. This method is the proper and more efficient way to do this.

driver.get("https://www.facebook.com/sachin-aryal/");
driver.findElement(By.name("xhpc_message_text")).sendKeys("Testing Java and Selenium");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button/span[.=\"Post\"]"))).click();

这篇关于Selenium和Facebook Post按钮:如何使用Selenium在Java中单击Facebook Post按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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