请帮助我了解如何使用硒访问“文件上传”(Google驱动器)
登录到Google驱动器后,单击“新建”将弹出一个包含选项“文件夹”,“文件上传”,“文件夹上传”等的弹出窗口,
我的问题是:如何访问“文件上载”(无法选择在浏览器中检查该元素)。
谢谢
答案 0 :(得分:1)
如果要更好地上传文件,请使用https://developers.google.com/drive/api/v3/manage-uploads。
该按钮的Xpath是:
#!/usr/bin/env python3
# https://stackoverflow.com/questions/52015836/updating-tkinter-label-based-on-loop
from tkinter import Tk, Label, Frame, Button, StringVar
import os
DELAY = 250 # Milliseconds between var updates.
def walk_dirs(start_dir):
""" Iteratively walk directory tree from start_dir. """
yield "Walking " + start_dir # Optional.
for root_directory, sub_directories, files in os.walk(start_dir):
for sub_directory in sub_directories:
full_directory = os.path.join(root_directory, sub_directory)
yield full_directory
def update_variable(var, walker):
try:
directory = next(walker)
except StopIteration:
var.set("DONE!")
return # Don't call after() so repetitive updates stop.
var.set(directory) # Setting var automatically updates Label.
tooltip.after(DELAY, update_variable, var, walker) # Rinse and repeat.
def start_command(var):
walker = walk_dirs("C:\\") # Start coroutine.
update_variable(var, walker) # Start periodic updates using it.
window = Tk()
var = StringVar()
var.set("Nothing Here Yet")
tooltip = Label(window, textvariable=var)
tooltip.pack()
start = Button(text="Start", command=lambda: start_command(var))
start.pack()
window.mainloop()
HTML:
.//div[.='File upload']
代码可能是:
<div class="h-v" role="menuitem" id=":2q" style="user-select: none;">
<div class="h-v-x">
<span class="h-v-c a-v-c a-v-c-mh">
<div>
<svg class="a-s-fa-Ha-pa" x="0px" y="0px" width="20px" height="20px" viewBox="0 0 20 20" focusable="false" fill="#000000">
<path d=""></path>
</svg>
</div>
</span>
<span class="a-v-j">
<span class="a-v-ff">
<div class="a-v-T">File upload</div>
</span>
</span>
</div>
</div>