Python Selenium“元素点击被拦截”

时间:2020-08-10 07:57:58

标签: python selenium

作为项目的一部分,我正在研究LinkedIn上的围巾, 我正在尝试实现硒来自动单击通过XPATH找到的对象。

我会尝试解释,希望它足够清楚。 以下Python脚本打开页面https://www.linkedin.com/mynetwork/,开始修饰每个用户名及其标题,然后将带有XPATH“ artdeco-button--secondary”的“ Connect”按钮添加到名为p。的数组列表中。 > 在p [num..click()上,将单击Connect,其num标识符将根据数组。

while True:
time.sleep(12)
print ("12 SEC")

#Store in Array to access it later
n = []
l = []
p = []

#Search the objects 
name_xpath = browser.find_elements_by_class_name('discover-person-card__name')
title_xpath = browser.find_elements_by_class_name('discover-person-card__occupation')
link_xpath = browser.find_elements_by_class_name('artdeco-button--secondary')

#Add to array 
for name in name_xpath:
    n.append(name)
for title in title_xpath:
    l.append(title)
for link in link_xpath:
    p.append(link)
time.sleep(12)

for num in range(0,len(n)):
    #print ("---")
    print ("Username:" + (n[num].text))
    print ("Title:" + (l[num].text))
    p[num].click()
    time.sleep(4)
browser.execute_script("window.scrollBy(0,2500)")

脚本输出成功完成,找到了用户名及其标题。 但是,到达点击部分时,会显示以下错误-

  raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button id="ember24" class="mr4 artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--secondary ember-view">...</button> is not clickable at point (449, 24). Other element would receive the click: <div class="search-global-typeahead__controls">...</div>

我检查了相同的问题,似乎--start-maximized参数应该可以解决此问题,但还是相同的问题。

chrome_options.add_argument("--start-maximized")

有什么想法吗?谢谢!

0 个答案:

没有答案
相关问题