【发布时间】:2020-12-22 04:12:39
【问题描述】:
我正在创建 Instagram 取消关注工具。该代码通常有效,但偶尔 Instagram 会显示某些用户的信息(就像我将鼠标悬停在该用户上方一样)并导致我的代码停止运行,因为它掩盖了我需要单击才能取消关注用户的按钮。
举个例子更容易理解:
如何编辑我的代码以使鼠标悬停信息消失(有没有办法关闭这些鼠标悬停效果)?
我的代码:
for i in range(num_following):
following = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[1]/div[2]/div[1]/span/a".format(i))
following_username = following.get_attribute("title")
if following_username not in followers:
# Unfollow account
following_user_button = self.browser.find_element_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[{}]/div/div[2]/button".format(i))
following_user_button.click()
unfollow_user_button = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]")
unfollow_user_button.click()
print("You've unfollowed {}.".format(following_username))
我得到的错误:
selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (781,461) 因为另一个元素遮住了它
【问题讨论】:
-
请您在问题中插入您的代码 sn-p 否则我们很难理解真正的问题。例如,为什么你的光标甚至在这个位置?发送
.click()或例如driver.execute_script("window.scrollTo(0, Y)")与 Selenium 不应该移动你的鼠标,那么为什么光标首先在那里? -
@J.M.Arnold 我已经添加了代码。我实际上并没有在屏幕上看到光标,但出现的弹出窗口与我将光标悬停在用户名上时出现的弹出窗口相同。通常我可以在弹出窗口出现之前取消关注多个帐户。
-
我试过了,我的光标又不动了,所以没有弹出窗口神奇地出现?此外,即使有一个,您仍然可以单击
Following按钮,就像在 Selenium 上使用Google Chrome WebDriver 87.0.4280.88尝试的那样。 -
@J.M.Arnold 我不知道为什么它对我不起作用。我收到以下错误:“selenium.common.exceptions.ElementClickInterceptedException:消息:元素在点 (781,461) 处不可点击,因为另一个元素遮住了它”。我刚刚在我的问题中添加了一个 GIF 以显示它的外观。 (运行程序时,我根本不移动光标。)
标签: python selenium webdriver instagram