【发布时间】:2021-08-03 04:09:05
【问题描述】:
我正在使用 Selenium 和 Python 来自动执行上传文件的过程。有一个“上传”按钮,默认情况下是禁用的,只有在选择要上传的文件时才能点击。
禁用按钮的 HTML 是 -
<button type="button" id="upload-button" data-bi-id="upload-button" class="ms-Button ms-Button--primary is-disabled root-296" disabled="" aria-label="Upload" aria-disabled="true" data-is-focusable="false">
按钮变为可点击后的 HTML 是 -
<button type="button" id="upload-button" data-bi-id="upload-button" class="ms-Button ms-Button--primary root-437" aria-label="Upload" data-is-focusable="true" tabindex="0">
我正在使用 -
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.ID,"upload-button"))).click()
但它不起作用。我相信这是单击禁用的按钮(即使选择了文件并且该按钮已变为可单击)。我也试过-
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.CLASS_NAME,"ms-Button ms-Button--primary root-437"))).click()
但这给出了TimeOut Exception。那么当这个按钮变成可点击后我应该怎么做才能点击它呢?我尝试了一些来自 Internet 的解决方案,但似乎都没有工作。
【问题讨论】:
-
By.CSS_SELECTOR 怎么样?
-
@MuhdMairaj 我也试过了......没有运气。我什至尝试过使用 XPATH。
-
您从哪里获得此 ID 值
profile.edit-picture.save-button。 ID 应该是这个upload-button -
@KunduK 哦,对不起......我在这里粘贴了错误的代码......这是我的错误......我现在就编辑它...... ...我在 id 中使用“上传按钮”
-
@AnshulVerma:有什么解决方案适合你吗?
标签: python selenium selenium-webdriver automation