Reputation: 624
I am creating a python program and it needs to be able to send a google hangouts message. I initially tried an API but found out these are only available for hangouts chat. So now I am trying selenium webdriver
. But I've run into a problem while trying to open a chat; the program gives me an error:
NoSuchElementException: no such element: Unable to locate element: {"method":"CSS selector","selector":"div.gS5QBe.R8jgRe"}
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)
My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
driver = webdriver.Chrome()
driver.get("https://hangouts.google.com/")
driver.find_element_by_id("gb_70").click()
elem = driver.find_element_by_id("identifierId")
elem.send_keys("my_username")
elem.send_keys(Keys.RETURN)
sleep(3)
pas = driver.find_element_by_css_selector("input.whsOnd")
pas.send_keys("my_password")
pas.send_keys(Keys.RETURN)
sleep(10)
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
driver.find_element_by_css_selector("div.gS5QBe.R8jgRe")
I have tried looking online but I cannot find a solution. Here is the website.
Upvotes: 1
Views: 514
Reputation: 8479
There will be lot of iframe in the page. Create locator for specific iframe which the element holds. I see the second iframe has new message button.
driver.switch_to_frame(driver.find_element_by_xpath("(//iframe)[2]"))
But i will recommend you to use Hangout API provided by google
Upvotes: 2