When I execute the code below, the interpreter displays running Process ended, but I receive no output on my headless browser.
from selenium import webdriver
driver = webdriver.Chrome("F:\\chromedriver.exe")
driver.get("https://www.google.com/maps")
driver.implicitly_wait(10)
menu = driver.find_element_by_xpath('//*[@id="omnibox-singlebox"]/div[1]/div[1]')
menu.click()
I also experiment with This XPath:
menu = driver.find_element_by_xpath('//*[@id="omnibox-singlebox"]/div[1]/div[1]/button')
CodePudding user response:
The Website is taking time to load. But the options are already available. And there is no difference in the attributes of the button
tag for menu before and after waiting time.
So waiting for the menu to clickable
does not have an effect. Applying some sleep time after the driver.get()
worked fine.
driver.get("https://www.google.com/maps/@12.3270885,76.6990167,15z")
time.sleep(10)
# wait = WebDriverWait(driver,30)
# wait.until(EC.element_to_be_clickable((By.XPATH,"//button[@class='searchbox-button']")))
menu = driver.find_element_by_xpath("//button[@class='searchbox-button']")
menu.click()
time.sleep(5)
CodePudding user response:
The menu element has a class searchbox-hamburger-container
which you can use to easily create a css selector for clicking the menu
Instead of this
menu = driver.find_element_by_xpath('//*[@id="omnibox-singlebox"]/div[1]/div[1]')
menu.click()
You can do this
menu = driver.find_element_by_css_selector("div.searchbox-hamburger-container")
menu.click()