无法通过selenium + java点击谷歌驱动器元素

时间:2017-09-05 11:52:48

标签: java xpath selenium-webdriver

当我试图点击谷歌驱动器下的文件夹时,他们每次都给我一个空,但我确定我的x路径是正确的,我的确认是由fire foxfox提供的,因为firefox接受我的x路径。

所以,任何身体都可以帮助我在这种情况下我能做些什么。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

在Chrome中尝试此代码,我也建议使用WebDriverwait而不是隐式等待,这里我使用隐式,因为您需要下载代码

System.setProperty("webdriver.chrome.driver", "E:\\software and tools\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://drive.google.com/drive/u/0/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//goto google drive

driver.findElement(By.xpath("html/body/section/div[2]/div/a")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// fill emailid
driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxxx");
//click on next
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
// fill password driver.findElement(By.xpath("//input[@name='password']")).sendKeys("xxxxxxx");
//click on next
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);


Actions act=new Actions(driver);
//move to download by right clicking and use your file xpath here    
act.contextClick(driver.findElement(By.xpath("//div[contains(text(),'Selenium Study')]"))).sendKeys(Keys.ARROW_DOWN).
sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN) 
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.RETURN).build().perform();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.close();

根据需要更改emailID,密码和Xpath