尽管python selenium中的文档中有可用元素,但该元素仍不可见 [英] element not visible despite availability in document in python selenium

查看:170
本文介绍了尽管python selenium中的文档中有可用元素,但该元素仍不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面链接:: https://联系人. google.com/u/1/?pageId=none

所需:我想通过点击所附图片中突出显示的SVG插入符号图标来选择所有联系人.

Desired: I want to select all contacts by clicking the highlighted SVG caret icon in attached image.

面临的问题:svgicon.click()上出现错误元素不可见.尽管根据所附图片,元素在可见的DOM中显然可用.

Problem facing : Getting error element not visible on svgicon.click(). Though element is clearly available in visible DOM as per image attached.

观察:我注意到,如果我们手动单击插入符号图标,则会通过JavaScript&在任何其他主体上,单击它都将删除DropDown html代码.

Observation : I have noticed that if we manually click on caret icon then DropDown html code is being inserted via JavaScript & on any other body click it is removing the DropDown html code.

我知道以下用于实现所需代码的代码是正确的&工作,但没有填充DropDown.非常感谢您的帮助.

I know following code statement used to achieve the desired is correct & working but not populating DropDown . Any help is much appreciated.

//find & click on SVG icon

svgicon = driver.find_element_by_css_selector('div.PFdmz .uzHa0d .RANAid[role="button"]')
svgicon.click()

//click on all link post dropdown appears
wait5.until(EC.presence_of_element_located((By.XPATH, '//div[@class = "jO7h3c" and text() = "All"]'))).click()

DOM图像

编辑1-示例Java脚本以选中所有复选框

t=0
for _ in range(len(driver.find_elements_by_css_selector('.XXcuqd div[role="checkbox"]'))):
    cimgs = driver.find_elements_by_css_selector('.XXcuqd div[role="checkbox"]')
    ActionChains(driver).move_to_element(cimgs[t]).perform()
    driver.execute_script("arguments[0].click();", cimgs[t])
    t = t+1

如果以某种方式我们可以使用此方法来减少标记所有复选框(代替使用Actionchains)所花费的时间,那么这也将解决问题.在任何时候,我都会有10000多个联系人参与此活动.

if somehow we can use this method to reduce time taken to mark all checkboxes checked (at one go in place of using Actionchains) then this will solve problem too. At any point of time i will have 10000+ contacts for this activity.

推荐答案

由于某些原因,您需要双击图标:

For some reason you need to double click the icon:

import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time

driver=webdriver.Firefox()
# Log into Google.
url = "https://accounts.google.com/signin/v2/identifier?hl=en&passive=true&continue=https%3A%2F%2Fwww.google.com%2F&flowName=GlifWebSignIn&flowEntry=ServiceLogin"
driver.get(url)
time.sleep(1)
username = driver.find_element_by_id('identifierId')
username.send_keys("REDACTED")
time.sleep(1)
driver.find_element_by_id('identifierNext').click()
time.sleep(1)
password = driver.find_element_by_name('password')
password.send_keys("REDACTED")
time.sleep(1)
driver.find_element_by_id('passwordNext').click()
time.sleep(1)

url="https://contacts.google.com/"
driver.get(url)
time.sleep(1)
# Select the first contact and click on it to open the desired menu.
contact = driver.find_element_by_css_selector("div[role='checkbox']")
contact.click()
time.sleep(1)
# Double click the selected action icon to open menu.
svgicon = driver.find_element_by_css_selector("div[data-tooltip='Selection actions']")
ActionChains(driver).move_to_element(svgicon).double_click().perform()
time.sleep(1)
# Click the "All" button.
selectall = driver.find_element_by_xpath("//*/div[text()='All']")
selectall.click()

这篇关于尽管python selenium中的文档中有可用元素,但该元素仍不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆