3

I'm trying to get inner html form an element. but I'm getting timeout exception in headless mode. If i disable headless, it works. I need the element in headless mode too.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
options = webdriver.ChromeOptions()
options.headless = True
browser = webdriver.Chrome(executable_path="./driver/chromedriver", options=options)
browser.get("https://inspiring-lewin-33088d.netlify.app")
try:
    element = WebDriverWait(browser, 10).until(
      expected_conditions.presence_of_element_located((By.ID, "zp"))
    )
    s = element.get_attribute('innerHTML')
    print(s)
finally:    
    browser.close()

I have tried other solutions like adding

options.add_argument("--window-size=1920,1080") options.add_argument('--start-maximized')

But they do not work. Your help Appreciated.

2 Answers 2

0

Updating chrome to v66 and chromedriver to v2.38 in combination with setting the following options:

ChromeOptions options = new ChromeOptions(); 
options.addArguments("--window-size=1920,1080"); 
options.addArguments("--disable-gpu"); 
options.addArguments("-- disable-extensions"); 
options.setExperimentalOption("useAutomationExtension", false); 
options.addArguments("--proxy-server='direct://'"); 
options.addArguments("--proxy-bypass-list=*"); 
options.addArguments("--start-maximized"); 
options.addArguments("--headless"); 

Should Solve the problem

Sign up to request clarification or add additional context in comments.

Comments

0

Replace presence_of_element_located with visibility_of_element_located to make sure the element is fully loaded. Then you should be safe to get_attribute('innerHTML'). In case you are not waiting for an element that will be visible ever (because its hidden), then apply this solution

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.