2016-08-02 76 views
-1
package javapackage; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
public class SeleniumQuora { 
public static void LaunchQuora() 
{ 
    System.setProperty("webdriver.chrome.driver","E:\\SBI SO\\Selenium\\Extracts\\chromedriver.exe"); 
    WebDriver driver=new ChromeDriver(); 
    driver.get("https://www.quora.com/"); 
    driver.manage().window().maximize(); 
    driver.manage().timeouts().implicitlyWait(13, TimeUnit.SECONDS); 
    driver.findElement(By.xpath("//*[@id='__w2_lIh8Ilg_google_connect_button']/span")).click(); 

    } 

public static void main(String[] args) { 
    LaunchQuora();}} 

这段代码应该点击signIn页面中的“Continue with Google”选项。但没有任何反应。我知道它非常基本,但我搜索了大部分地方,找不到答案。我的硒webdriver脚本不能在Chrome上工作

+1

你所说的 “什么也没发生” 的意思是?没有浏览器窗口打开?怎么样记录输出?堆栈跟踪?你如何调用什么操作系统的测试? –

+0

没有弹出窗口显示,应该问我继续我的谷歌ID。 –

回答

0

其实你是定位错误的元素,在这个website有id为__w2_lIh8Ilg_google_connect_button因为我看到没有元素,可提供动态生成的ID,所以,如果你想点击Continue with Google按钮简单地尝试如下使用By.linkText(): -

System.setProperty("webdriver.chrome.driver","E:\\SBI SO\\Selenium\\Extracts\\chromedriver.exe"); 

ChromeOptions options = new ChromeOptions(); 
options.addArguments("--disable-popup-blocking"); 
WebDriver driver = new ChromeDriver(options); 

driver.get("https://www.quora.com/"); 
driver.manage().window().maximize(); 
driver.manage().timeouts().implicitlyWait(13, TimeUnit.SECONDS); 
driver.findElement(By.linkText("Continue with Google")).click(); 

希望它能帮助.. :)

+0

完美。它的工作,谢谢你Saurabh。出于好奇,我可以问一下,如果我必须使用xpath,我会怎么做? –

+0

@ShashankShukla没有必要使用'xpath',但是如果需要xpath,你可以使用xpath来代替id,因为id是在这里动态生成的,你可以使用这个'xpath':'// a [@class =' google_button submit_button']' –