Selenium Webdriver python headless does not identify elements

Asked

Viewed 287 times

0

Good afternoon, I am programming a python file using Lenium. I reached my goal and the file ran smoothly. I went further and decided to use the headless, already at the beginning of the file execution I get an error:

in check_response raise exception_class(message, screen, stacktrace) Selenium.common.exceptions.Nosuchelementexception: Message: no such element: Unable to locate element: {"method":"css selector","selector":". whsOnd zHQkBf"} (Session info: headless Chrome=86.0.4240.198)**

Indicating that he was not able to identify the element on the page, only that this error persists also when trying to use the selector xpath, class, full xpath and id.

My code:

from time import sleep
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=options, executable_path='C:/Users/Thunder/drivers/chromedriver.exe')
driver.get('https://classroom.google.com/u/1/c/MTIzNzc4MTM2NjY5')
sleep(8)
logan = driver.find_element_by_id('identifierId')
logan.send_keys('e-mail')
logan.send_keys(u'\ue007')
  • Have you tried using the option = Options() | option.headless = True?

  • Can specify better?

1 answer

0

Hello! To further specify my comment I will post what I imagine to be the answer, so I saw in your code you did not import Chrome options, I imagine that only solves your problem:

from selenium.webdriver.chrome.options import Options

If that doesn’t solve try to put that line of code in place of your 4°line:

option = Options()
option.headless = True

If the problem is the headless will run straight, because from what I understand the code worked only that when you went to use the headless did not work anymore

  • It didn’t work, buddy. Deprecationwarning: use options Instead of chrome_options driver = webdriver.Chrome(executable_path='C:/Users/Thunder/drivers/chromedriver.exe', chrome_options=option)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.