Im trying to get headless chrome to work and I just cant get it to work. I created a test file which works:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)
driver.get('http://www.google.com')
print(driver.title)
it works but also produces an error:
C:/Users/kgood/PycharmProjects/pythonProject1/Unknown.py:6: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)
I can live with the error I suppose because it does open headless, gets Chrome, prints the title like I asked, but when I go to paste this into my main project, it still opens a window, the window is blank, and it just sits there as a blank window until its finished running. Any ideas whats going on? Here is the beginning of my project code:
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
options = webdriver.ChromeOptions()
options.add_argument("--headless")
# gets the website
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe" , chrome_options=options)
driver.get("https://www.legacyhomesal.com/pennington-freedom-series-richmond-ii")
# finds the Base Price header
price = driver.find_element_by_xpath("//h3[@class='ng-binding']")
print(price.text)
# converts the string to integer
p = price.text[12::]
r = int(p.replace(',', ''))
driver.close()
I have tried multiple different ways of doing this but only the one above, kinda works:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu') # Last I checked this was necessary.
driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)
and
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)