How to open gmail and other menus from Google Apps menu using python selenium

0 votes

Hello,

I want to open Gmail and other apps from google home page using python and selenium.

I am able to open 'Google Apps' with Xpath but not able to locate google apps like Gmail, Drive, YouTube, Account and other.

I tried with the code;

menu1 = driver.find_element_by_xpath("//*[@id='gbwa']/div[1]/a")
menu1.click() 
menu2 = driver.find_element_by_xpath("//*[@id='gb23']/span[1]")
menu2.click() 

Here menu2 is to click 'Gmail' available in apps. It works once but then every time it gives an error 

selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable

I tried by 

  1. Putting wait  
  2. Using Xpath Contains 
  3. Switch_to_Window, Frame and other

but facing the same issue.

Any suggestions.

Thanks in Advance.

Jul 31, 2019 in Python by ADS
• 280 points

edited Jul 31, 2019 by Omkar 2,663 views

1 answer to this question.

+1 vote

You have to add implicit wait until that button is clickable because that button loads only after you click the menu icon. This code works:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"))
driver.get("http://www.google.com")

apps=driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/a[1]")
apps.click()

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//a[@id='gb23']//span[@class='gb_m']")))

element.click();
answered Jul 31, 2019 by Rishi
Thanks Rishi !

Well, I used the same code but for apps I used this Xpath ( I put Xpath as //*[@id="gbwa"]/div[1]/a.) and with that it ran for once but then locator visibility issue was throwing by the system.

Is that necessary to use firebug and not the F12 for chrome ?

Looks like you are using a wrong xpath. I tried "//a[@class='gb_z gb_rc']" and it worked.

Hi, I got same Xpath by Xpath Helper and F12.
I used ChroPath to find the Xpath. Give it a try.
Checked that ! Thanks Bro...
Did it work?
Yo ! It worked

Related Questions In Python

+1 vote
2 answers

How to automate image upload from my computer to site using python-selenium?

Hey, this code worked for me: image_path=os.path.abspath('.\\folder1\\subfolder2\file1.jpg') driver.find_element_by_id("Id of ...READ MORE

answered Aug 19, 2019 in Python by Rishi
5,683 views
0 votes
0 answers

How to click on the main menu and sub menu using python script

How to proceed with main menu and ...READ MORE

Oct 6, 2020 in Python by ParthivPatel
• 140 points
1,161 views
0 votes
1 answer

How to get text label from SAP using pywinauto[python]

Hi. Can you please tell me what ...READ MORE

answered Jun 28, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,308 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,707 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,605 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,679 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,547 views
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21, 2019 in Python by Nymeria
• 3,560 points
7,706 views
+1 vote
1 answer

How to install tensorflow using anaconda and python 3.7.1 on windows?

Since I am using python 3.5 so ...READ MORE

answered Aug 19, 2019 in Python by Arvind
• 3,040 points
8,868 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP