我正在尝试使用selenium制作脚本,将文件从本地磁盘上载到google驱动器。成功登录并点击google drive桌面版上的new按钮之前我是成功的,但之后我无法选择出现在new小窗口下的选项(按下new按钮后出现的窗口)
我的代码到现在为止:
#!/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<mpl=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()
这可能会有所帮助-因此您需要使用窗口句柄切换到新的浏览器实例。我不知道这是否只适用于Windows系统。你知道吗
抱歉,下面的代码是Java语言:
关于这个答案,请参阅源文章here。你知道吗
相关问题 更多 >
编程相关推荐