0

I'm trying to make the script for uploading the files from my local disk to google drive using selenium. I am success upto successful login and clicking new button on google drive desktop version but after that I am not able to select option that appears under new small window ( window that appears after 'new' button is pressed )

My code till now:

#!/usr/bin/python
    from selenium import webdriver
    import time
    from selenium.webdriver.common.keys import Keys

    browser=webdriver.Firefox()
    #gdURL='https://drive.google.com'
    gdURL='https://accounts.google.com/ServiceLogin?service=wise&passive=true&   continue=http%3A%2F%2Fdrive.google.com%2F%3Futm_source%3Den_US&  utm_medium=button&utm_campaign=web&utm_content=gotodrive&usp=gtd&ltmpl=drive'
   browser.get(gdURL)
   def idIn(email):
       gId=browser.find_element_by_id('identifierId')
       gId.send_keys(email)
       gId.send_keys(Keys.ENTER)
       time.sleep( 10 )
   def passIn(passwd):
       gPass=browser.find_element_by_name('password')
       gPass.send_keys(passwd)
       gPass.send_keys(Keys.ENTER)
       time.sleep( 30 )
   if browser.find_element_by_id('identifierId'):
       idIn('myemail')
       passIn('mypassword')
   #if browser.find_element_by_name('password'):
   #   passIn('mypassword')
   btn=browser.find_elements_by_tag_name('button')
   btn[4].click()
rcShahi
  • 91
  • 7

2 Answers2

0

There is a method to handle alerts in selenium - driver.switch_to_alert() this docs should help you out https://seleniumhq.github.io/selenium/docs/api/py/webdriver/selenium.webdriver.common.alert.html#module-selenium.webdriver.common.alert

Dhiraj Das
  • 174
  • 9
  • i guess it's not related with alert window. I just want to deal with window that stick with main windows and prompt you to upload file – rcShahi Dec 02 '17 at 16:42
  • As far as I know, you don't have a native switch to upload file prompt window, You can use the same switch to alert to verify the text and then, click on the buttons available. – Dhiraj Das Dec 03 '17 at 16:44
0

This may help - So you need to switch to the new browser instance using window handles. I don't know if this only works in Windows systems though.

Apologies, the code below is in Java:

// Store the current window handle 
String winHandleBefore = driver.getWindowHandle(); 
// Perform the click operation that opens new window 
// Switch to new window opened 
for(String winHandle : driver.getWindowHandles()){ 
driver.switchTo().window(winHandle); } 
// Perform the actions on new window 
// Close the new window, if that window no more required driver.close(); 
// Switch back to original browser (first window) 
driver.switchTo().window(winHandleBefore); 
//continue with original browser (first window)

See the source post for this answer here.

hjr2000
  • 143
  • 1
  • 10