I'm trying to start a selenium application (with python) via webdriver.Remote()
, like they recomends on documentation, but when I run the code below, I get the following error message:
selenium.common.exceptions.WebDriverException: Message: default backend - 404
My code is here:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability("platformName", "LINUX")
chrome_options.set_capability("browserName", "chrome")
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
prefs = {"download.default_directory": 'downloads'}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=chrome_options.to_capabilities()
)
driver.get("http://www.google.com")
search_box = driver.find_element_by_name('q')
search_box.send_keys('stackoverflow')
search_box.submit()
driver.quit()
I've already tried to remove the options and use only the recommended code, as below, but I got the same problem.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)
driver.get("http://www.google.com")
search_box = driver.find_element_by_name('q')
search_box.send_keys('stackoverflow')
search_box.submit()
driver.quit()
CodePudding user response:
I found the solution to the problem and it is related to command_executor
. Whenever you need to declare this argument, don't put http
or https
before the address. So the correct code is:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.set_capability("platformName", "LINUX")
chrome_options.set_capability("browserName", "chrome")
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
prefs = {"download.default_directory": 'downloads'}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Remote(
command_executor='127.0.0.1:4444/wd/hub',
desired_capabilities=chrome_options.to_capabilities()
)
driver.get("http://www.google.com")
search_box = driver.find_element_by_name('q')
search_box.send_keys('stackoverflow')
search_box.submit()
driver.quit()
Or the simpler code:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
command_executor='127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME
)
driver.get("http://www.google.com")
search_box = driver.find_element_by_name('q')
search_box.send_keys('stackoverflow')
search_box.submit()
driver.quit()