【发布时间】:2021-07-31 22:52:35
【问题描述】:
所以,我要做的是自动化一个过程,该过程打开 Microsoft 登录页面,输入登录信息,然后登录。之后,它点击个人资料,然后点击更改个人资料图片按钮。 现在,我在下一部分遇到了麻烦......这是上传图片并将其设置为个人资料图片。 我搜索了整个互联网,但找不到解决方案。
到目前为止,我的代码是 -
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
chromedriver = 'C:\\Users\\verma\\Downloads\\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
action = ActionChains(browser)
#1. Open Microsoft Login Page
browser.get('https://www.microsoft.com/en-in/?wa=wsignin1.0')
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID,"mectrl_headerPicture"))).click()
#2. Login with Username and Password
user = (By.ID,"i0116")
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(user)).send_keys("emailid@outlook.com")
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID,"idSIButton9"))).click()
password = (By.ID,"i0118")
WebDriverWait(browser, 10).until(EC.element_to_be_clickable(password)).send_keys("password")
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID,"idSIButton9"))).click()
#3. Click on Profile and then Click on Change Picture
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID,"mectrl_headerPicture"))).click()
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID,"mectrl_currentAccount_picture_profile_picture"))).click()
#4. Upload Picture
time.sleep(5)
browser.quit()
我尝试过的是-
#4. Upload Picture
WebDriverWait(browser, 30).until(EC.element_to_be_clickable((By.ID,"id__62"))).click()
windows 文件选择器没有弹出。我的猜测是我为“选择文件”按钮/链接到 selenium 提供了错误的 ID,这就是它给出 TimeoutException 的原因,因为它找不到元素。 但我似乎找不到正确的 ID。我也想知道文件选择器弹出成功后怎么上传图片。
编辑:HTML 代码的屏幕截图(通过检查)
【问题讨论】:
-
以文本格式分享您的 HTML 代码以便更好地理解。
-
@cruisepandey 共享整个 HTML 代码会很忙....但我现在包含了 HTML 的屏幕截图(检查)。高亮部分显示id
-
好的,我用自己的凭据登录,看起来我们需要切换到另一个选项卡,然后在那个新选项卡中我看到一个带有文件属性的输入标签。将恢复。
-
@cruisepandey 那么我必须在这里做什么?对不起,我不明白
-
你能点击
Add a photo链接吗?
标签: python selenium file-upload selenium-chromedriver