Unable to Click a folder in Google Drive

90 views
Skip to first unread message

Divya Reddy

unread,
Dec 6, 2016, 8:41:43 AM12/6/16
to Selenium Users
Hi,

Am New to selenium,can some one help me to resolve the below issue.
Requirement
1.LogIn to Google Drive
2.Search the required folder by placing the folder name in the search box of the drive
3. Click on the Folder it not working after search.
Below is the code i used.

            //navigate to google drive
            driver.get("https://drive.google.com/");
           
            //Login to google drive
            driver.findElement(By.id("Email")).sendKeys(" ");
            driver.findElement(By.id("next")).click();
            wait.until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")));
            driver.findElement(By.id("Passwd")).sendKeys(" ');
            driver.findElement(By.id("signIn")).click();
           
             wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("q"))));
            driver.findElement(By.name("q")).sendKeys("FolderName");    
            driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
            Thread.sleep(7000);

          //Below code is not working
          wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("//span[contains(text(),'"+FolderName+"')]"))));

It would be really helpful if someone helps to resolve this

⇜Krishnan Mahadevan⇝

unread,
Dec 6, 2016, 10:49:07 AM12/6/16
to Selenium Users
Divya,

Why would you want to use Selenium to interact with Google drive, when Google exposes APIs to do the same ?

You might want to start looking from here : https://developers.google.com/drive/v2/reference/

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9dd02de3-2ec8-4f5b-9b98-df2b5789bb52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ahmet Ozkesek

unread,
Dec 6, 2016, 2:15:10 PM12/6/16
to Selenium Users
Hi Divya,

I agree with Krishnan.

At the same time I've also done a little bit investigation on your code. 
After some changes, this code has started to work without an error for me,

 WebDriver driver = new FirefoxDriver();

 driver
.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

 
WebDriverWait wait = new WebDriverWait(driver, 20000);
 
 driver
.get("https://drive.google.com/");

         

 
try {

         
//Login to google drive

         driver
.findElement(By.id("Email")).sendKeys(" ");

         driver
.findElement(By.id("next")).click();

         wait
.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));

         driver
.findElement(By.id("Passwd")).sendKeys(" *** ");

         driver
.findElement(By.id("signIn")).click();

         

         
//wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("q"))));

         driver
.findElement(By.name("q")).sendKeys("FolderName");      

         driver
.findElement(By.name("q")).sendKeys(Keys.ENTER);

         
try {

 
Thread.sleep(7000);

 
} catch (InterruptedException e1) {

 
// TODO Auto-generated catch block

 e1
.printStackTrace();

 
}

 

         
WebElement folder = driver.findElement(By.xpath("//span[contains(text(),'FolderName')]"));

         folder
.click();

       
//Below code is not working
// same as mine,
// i did not understand yet but there were lot strange debug log while waiting for condition of element-to-clickable
 
// so i removed that condition

       
//wait.until(ExpectedConditions.elementToBeClickable(folder));

       folder
.sendKeys(Keys.ENTER);

// now i can see the files and sub folders under the FolderName


To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Divya Reddy

unread,
Dec 7, 2016, 7:27:08 AM12/7/16
to Selenium Users
Hey Ahmet,

Thanks for looking into it.

I tried the code change that you have suggested but no luck :(.

Attached is the exception that am facing at floder.click() function.

you any idea why this comes?
exception.PNG

Divya Reddy

unread,
Dec 7, 2016, 7:29:32 AM12/7/16
to Selenium Users
Krishna,

My requirement is to download a folder from Drive automatically on scheduled basis.So i picked selenium to do perform this activity as we create a job which runs for us on scheduled basis

thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Dec 7, 2016, 8:55:59 AM12/7/16
to Selenium Users
Divya,

But what I would still like to understand is why do you need Selenium to do this for you, when Google provides you a much more straight forward way of doing this via RestFul APIs ?

You can still run your RestFul invocations via your scheduled jobs no ? [ Am guessing you are referring to a job within Jenkins when you say job ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c7728a07-9bf6-4880-85e2-191559dc5434%40googlegroups.com.

Ahmet OZKESEK

unread,
Dec 7, 2016, 10:28:28 AM12/7/16
to Selenium Users
Hi Divya,

The exception says basically you should add a condition and wait the element is been visible before you try to get it.

wait.until(ExpectedConditions.visibilityOfElementLocated(By.???("???")));
 
I also read Krishna and you.  
What I suggest you is same as Krishna.  
If you want to run this in PRODUCTION ENVIRONMENT with a MISSION CRITICAL JOB you should use the google rest api.  

AO

Ahmet OZKESEK

unread,
Dec 7, 2016, 10:34:55 AM12/7/16
to Selenium Users
BTW, I am so sorry for wrong typing of Krishnan's name.
Reply all
Reply to author
Forward
0 new messages