单击Facebook';共享';使用SeleniumJava的按钮
我必须测试这个FB按钮: Facebook按钮位于iframe中。我切换到iframe,我可以找到“共享”按钮。但是当webDriver单击它时,弹出窗口不会显示。我的代码是:单击Facebook';共享';使用SeleniumJava的按钮,java,facebook,selenium-webdriver,webdriver,automated-tests,Java,Facebook,Selenium Webdriver,Webdriver,Automated Tests,我必须测试这个FB按钮: Facebook按钮位于iframe中。我切换到iframe,我可以找到“共享”按钮。但是当webDriver单击它时,弹出窗口不会显示。我的代码是: WebElement iframeFacebook = webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div[3]/iframe[1]")); webDriver.switchTo().frame(iframeFacebook); webDri
WebElement iframeFacebook = webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div[3]/iframe[1]"));
webDriver.switchTo().frame(iframeFacebook);
webDriver.findElement(By.xpath("//span[contains(@class, 'pluginButtonLabel') and contains(., 'Share')]")).click();
webDriver.switchTo().defaultContent();
我对Twitter按钮也做了同样的处理,而且效果很好。FB按钮有什么特别之处
编辑
FB按钮的HTML代码:
<iframe frameborder="0" allowtransparency="true" style="border:none; overflow:hidden; width:97px; height:35px; float:left" scrolling="no" src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Ffacebook.com%2Fmynumber26&width&layout=button&action=like&show_faces=false&share=true&height=35&appId=1454011268146569&locale=en_US">
<!DOCTYPE html>
<html id="facebook" class="" lang="en">
<body class="plugin gecko win x1 Locale_en_US" dir="ltr">
<div class="_li">
<div class="pluginSkinLight pluginFontHelvetica">
<div>
<table class="uiGrid _51mz pluginConnectButtonLayoutRoot _3c9t" cellspacing="0" cellpadding="0">
<tbody>
<tr class="_51mx">
<td class="_51m- hCent">
<td class="_51m- pluginButtonSpacer">
<div class="pluginButton pluginButtonSmall" onclick="require(" Popup ").open("\/sharer.php?u=http\u00253A\u00252F\u00252Ffacebook.com\u00252Fmynumber26&display=popup&ref=plugin&src=share_button&app_id=1454011268146569 ", 670, 340);">
<div>
<div class="pluginButtonContainer">
<div class="pluginButtonImage">
<span class="pluginButtonLabel">Share</span>
</div>
</div>
</div>
</div>
</td>
<td class="_51m-"></td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
</iframe>
分享
也许您的xpath没有找到IframeFacebook,而是找到了按钮。第一次单击是设置焦点
尝试添加另一次单击以查看是否存在这种情况。如果是,请尝试为Iframe使用标记名或ID定位器
如果你想让生活更轻松,可以尝试:
另外,不是为了说教,但使用Xpath定位器作为最后手段是一般的最佳实践
也许您的xpath没有找到IframeFacebook,而是找到了按钮。第一次单击是设置焦点 尝试添加另一次单击以查看是否存在这种情况。如果是,请尝试为Iframe使用标记名或ID定位器 如果你想让生活更轻松,可以尝试: 另外,不是为了说教,但使用Xpath定位器作为最后手段是一般的最佳实践
我已经核实过了。它不在iframe中 使用下面的逻辑
String postNo="1"; // To click on share of first post in timeline
driver.findElement(By.xpath("//div[contains(@id,'substream')]["+postNo+"]//span[@class='share_root']//span[text()='Share']")).click();
driver.findElement(By.xpath("//div[contains(@id,'substream')]["+postNo+"]//span[@class='share_root']//span[text()='Share']")).click();
//click on =>(Share Now friends) with below locator
By.xpath("//ul[@role='menu']//span[text()='Share Now (Friends)']")
//click on =>Share...
By.xpath("//ul[@role='menu']//span[text()='Share…']")
编辑-I
如果我们点击共享链接,它不会打开下面的选项(不知道为什么?!)。尝试单击两次。我已经验证过了。它不在iframe中 使用下面的逻辑
String postNo="1"; // To click on share of first post in timeline
driver.findElement(By.xpath("//div[contains(@id,'substream')]["+postNo+"]//span[@class='share_root']//span[text()='Share']")).click();
driver.findElement(By.xpath("//div[contains(@id,'substream')]["+postNo+"]//span[@class='share_root']//span[text()='Share']")).click();
//click on =>(Share Now friends) with below locator
By.xpath("//ul[@role='menu']//span[text()='Share Now (Friends)']")
//click on =>Share...
By.xpath("//ul[@role='menu']//span[text()='Share…']")
编辑-I
如果我们点击共享链接,它不会打开下面的选项(不知道为什么?!)。尝试单击两次。请发布按钮的相关HTML以及您认为有用的任何其他内容。@JeffC,我在发布HTML时添加了HTML代码。请花一分钟时间使用美化工具,如正确格式化。它使阅读更容易,使你的问题更有可能得到回答。谢谢请发布按钮的相关HTML以及您认为有用的任何其他内容。@JeffC,我添加了HTML代码当您发布HTML时,请花一分钟时间使用美化工具(如正确格式化)。它使阅读更容易,使你的问题更有可能得到回答。谢谢谢谢你的帮助,但我不点击FB本身,我们的网络应用程序有一个按钮共享,一个插件,当你点击时,你必须登录到你的FB和共享。我添加了HTML代码谢谢你的帮助,但我没有点击FB本身,我们的webapp有一个按钮共享,一个插件,当你点击时,你必须登录到你的FB并共享。我添加了HTML代码感谢帮助,但是在我们使用的插件中,没有ID或任何相同的标签,很容易找到。我添加了pluginThank的HTML以寻求帮助,但在我们使用的插件中,没有ID或任何相同的标签,很容易找到。我添加了插件的HTML