import time,os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(chrome_options=chrome_options)
target = "https://pan.baidu.com/"
driver.get(target)
name='name'
passwd='passwd'
driver.find_element_by_xpath('//div[@class="account-title"]/a').click()
driver.find_element_by_xpath('//input[@id="TANGRAM__PSP_4__userName"]').send_keys(name)
driver.find_element_by_xpath('//input[@id="TANGRAM__PSP_4__password"]').send_keys(passwd)
driver.find_element_by_xpath('//input[@id="TANGRAM__PSP_4__submit"]').click()
upload_page = driver
try:
path1 = driver.find_element_by_xpath('//a[@title="test1"]')
ActionChains(driver).move_to_element(path1).perform()
ActionChains(driver).context_click(path1).perform()
driver.find_element_by_xpath('//*[@class="context-menu"]/ul/li[21]').click()
time.sleep(5)
driver.find_element_by_xpath('//*[@class="g-button g-button-blue-large"]/span/span').click()
time.sleep(3)
except:
pass
try:
path2 = driver.find_element_by_xpath('//a[@title="test2"]')
ActionChains(driver).move_to_element(path2).perform()
ActionChains(driver).context_click(path2).perform()
driver.find_element_by_xpath('//*[@class="context-menu"]/ul/li[21]').click()
time.sleep(5)
driver.find_element_by_xpath('//*[@class="g-button g-button-blue-large"]/span/span').click()
time.sleep(5)
except:
pass
上面的程序执行了几个步骤:
1.登录百度网盘
2.删除test1文件
3.删除test2文件
在python3 terminal中,复制一行一行的运行没有任何问题。
将上面的代码保存成一个文件 up.py
time python3 up.py
出现两个问题:
1.运行时间
time python3 up.py
real 0m4.231s
user 0m0.192s
sys 0m0.080s
2.运行结果
test2没有删除
请问,如何处理?