Skip to content Skip to sidebar Skip to footer

Element Not Visible Despite Availability In Document In Python Selenium

Page Link : https://contacts.google.com/u/1/?pageId=none Desired: I want to select all contacts by clicking the highlighted SVG caret icon in attached image. Problem facing : Gett

Solution 1:

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()

Solution 2:

In your first code example,

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

the selector matches four elements, and the checkbox you are looking for is the fourth. If you haven't already, please try

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

instead of that line.

I'm immediately sure about the JS executor but could take a look if the above code doesn't work.

Solution 3:

I don't know why but Dan-dev's code performs the result you need, I have tried it and it works fine for me. In this case I'll just put another alternative to what I have done before when I encountered a similiar problem like yours might somehow work for you. Here's my code:

from selenium.webdriver.support.ui import Select


#From Dan-dev's code
svgicon = driver.find_element_by_css_selector("div[data-tooltip='Selection 
actions']")
ActionChains(driver).move_to_element(svgicon).double_click().perform()

#Alternative/Optional Solution
driver.execute_script("return arguments[0].removeAttribute('style');", svgicon)
selectall = Select(svgicon)

for option in selectall.options:
 selectall.select_by_visible_text('All')

Solution 4:

Well, after investing 15+ days in research, learning & SO community help, nothing worked as expected hence i had to go to 2nd option (undesirable) to meet the purpose.

Working answer

# get total contacts count from left side menu displayed number
totalcount = driver.find_element_by_css_selector('span.jlpDMe[dir="ltr"]').get_attribute('innerHTML')
time.sleep(1)
cimg = driver.find_elements_by_css_selector('div.XXcuqd div[role="checkbox"]')
#t=1 because **div[data-tooltip='Selection actions']** is also a checkbox & we don't want that to be a part of loop
t=1 
while t < int(totalcount)+1:
    driver.execute_script("arguments[0].click();", cimg[t])
    t+= 1

This method is way faster than using Actionchains i had shown in EDIT 1 - Sample Javascript effort to select all checkboxes.

Anyway, thanks everyone for putting your mind to solve a puzzle though it's still a puzzle to me. But considering amount of efforts put up by everyone, bounty owner is @Dan-Dev. Thanks @Dan-Dev & keep helping people like us.

Post a Comment for "Element Not Visible Despite Availability In Document In Python Selenium"