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 in Python by ADS
• 280 points

edited Jul 31 by Omkar 85 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 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 in Python by Rishi
44 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
408 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,900 points
69 views
0 votes
1 answer

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,090 points
750 views
0 votes
1 answer
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,130 points
995 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
709 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 in Python by Nymeria
• 3,520 points
565 views
0 votes
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 in Python by Arvind
• 2,960 points
115 views