按鈕,我一定要考這個FB按鈕:點擊Facebook的 '分享' 與硒的Java
的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);
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>
請發佈按鈕的相關HTML和其他你認爲有用的東西。 – JeffC
@JeffC,我添加了HTML代碼 – Ragnarsson
當您發佈HTML時,請花一點時間使用像http://jsbeautifier.org/這樣的美化工具來正確格式化它。它使得它更容易閱讀,這使得你的問題更可能得到解答。謝謝! – JeffC