Selenium WebDriver – Java – 单击按钮

我正在尝试点击一些按钮,我正在使用twitch上的Follow按钮作为示例。

我使用Selenium IDE尝试获取按钮的xpath。 我得到的xpath是: //span[@id='ember637']/a/span

如果我去FireFox并为按钮复制唯一选择器我得到: .js-follow > span:nth-child(1)

我已经在java程序中尝试过它们并且它们不起作用。 当我使用//span[.. xpath时,我收到以下错误:

 "Unable to locate a node using //span[@id='ember637']/a/span" 

编辑:

带有我想点击的按钮的网站示例(“关注”按钮): http : //www.twitch.tv/mradder89/profile/

我正在使用的Selenium jar文件是“selenium-server-standalone-2.35.0.jar”

我得到的错误是

 "Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate a node using //span[@id='ember637']/a/span" 

编辑2:

我下载了PhantomJSDriver exe文件(phantomjs.exe)并试用了它。 它不起作用…我没有像以前那样得到错误消息(“无法找到节点…”错误)。

这是代码: http : //pastebin.com/GzvubMZr

使用PhantomJSDriver,尝试不同的定位器。 发布例外(如果有),否则发布元素的信息,例如位置,文本等。

 driver.findElement(By.xpath("//*[contains(@class, 'profile-actions')]//span[text()='Follow']")).click(); driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();