【发布时间】:2021-04-27 23:06:10
【问题描述】:
我在单击 Selenium 按钮时遇到问题。我以前从未使用过 Selenium,所以我尝试在网上搜索解决方案,但没有运气。我尝试了其他一些东西,例如 WebDriverWait,但没有任何效果。
# My Code
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
PATH = "F:\SeleniumProjects\chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument("start-maximized");
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(options=options, executable_path=PATH)
driver.get("https://www.discord.com")
time.sleep(3)
buddy = driver.find_element_by_xpath("/html/body/div/div/div/div[1]/div[1]/header[1]/nav/div/a")
ActionChains(driver).move_to_element(buddy).click().perform()
这个异常让我感到困惑,因为我知道我可以与之交互,但我不确定为什么它说它不是。我确信有一些简单的解决方法,但我很难过。
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: https://discord.com/login has no size and location
(Session info: chrome=90.0.4430.93)
这是我要按下的按钮
<a class="button-195cDm buttonWhite-18r1SC buttonSmall-2bnF7I gtm-click-class-login-button button-1x6X9g mobileAppButton-2dMGaq" href="//discord.com/login">Login</a>
【问题讨论】:
-
我想知道您的 URL 窗口是否没有显示,因为它显示
element not interactable: https://discord.com/login has no size and location,您可以尝试在driver.get之后使用driver.set_window_size(1920, 1080)之类的东西指定窗口的尺寸吗? /跨度>
标签: html python-3.x selenium selenium-webdriver