Error: The host is experiencing an AttributeError because the 'Service' object does not have the attribute 'process' available

Looking to scrape a website using Python on a host without GUI. Unfortunately, the webpage I want to scrape ( ) does not allow scraping with the requests library, so I have to resort to using Selenium with a headless webdriver. (Apologies for any language errors!)

Here's the code I ran on a cPanel host via terminal:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options

chrome_options = Options()  
chrome_options.add_argument("--headless")
with Chrome(options=chrome_options) as driver:
    driver.get("https://aqms.doe.ir/App/")
    sleep(10)
    refresh = driver.find_element(By.XPATH, '/html/body/app-root/app-toolbar/div/div/app-toolbar-port/mat-toolbar/mat-toolbar-row[1]/button[2]/span/mat-icon')
    refresh.click()
    sleep(10)
    shn = driver.find_element(By.CSS_SELECTOR, '#highcharts-29 > div > div:nth-child(1) > span > div > span:nth-child(1)').text
    print(shn)

NOTES:

I have installed Selenium on the host using the terminal. and the chromewebdriver.exe is in the same folder as the code file (both the source and chromedriver are located in one folder). I executed this code by creating an application in cPanel using 'setup python' and running it in the terminal.

However, I encountered this Error:

File "req2.py", line 10, in <module>
    with Chrome(options=chrome_options) as driver:
File "/home/gigachad/virtualenv/python_bot/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().init(
File "/home/gigachad/virtualenv/python_bot/3.8/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in init__
    self.service.start()
File "/home/gigachad/virtualenv/python_bot/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 106, in start
    self.assert_process_still_running()
File "/home/gigachad/virtualenv/python_bot/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
    return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'

I believe this error might be due to the way it was run on the host.

Thank you!

Answer №1

To utilize the Chrome driver in Selenium, you must provide a Service object as an argument to Chrome(). This service should point to the installation location of the chromedriver binary object.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

chrome_options = Options()  
chrome_options.add_argument("--headless")
with Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options) as driver:
    driver.get("https://aqms.doe.ir/App/")
    sleep(10)
    refresh = driver.find_element(By.XPATH, '/html/body/app-root/app-toolbar/div/div/app-toolbar-port/mat-toolbar/mat-toolbar-row[1]/button[2]/span/mat-icon')
    refresh.click()
    sleep(10)
    shn = driver.find_element(By.CSS_SELECTOR, '#highcharts-29 > div > div:nth-child(1) > span > div > span:nth-child(1)').text
    print (shn)

Additional Resources

For more detailed discussions on this topic, check out these references:

  • DeprecationWarning: executable_path has been deprecated selenium python
  • DeprecationWarning: executable_path has been deprecated, please pass in a Service object

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to execute a unit test from within another unit test?

Currently, I am in the process of developing Python x Selenium unit tests specifically for testing the login feature of a particular website. One challenge I encountered is writing a test case for the "Remember Me" functionality after successfully creati ...

The execution of the selenium script is unreliable

Recently, I created a selenium script to automate certain manual checks on http:obsessory.com. The script utilizes a looping concept, such as mouse hovering over the Top menu and clicking on various submenus. However, during testing, I have encountered spo ...

Find the button for uploading files using Selenium

I am encountering an issue with trying to click the button displayed below (image and HTML). Despite attempting to locate it using both xpath and ID, Selenium is still unable to find it. https://i.stack.imgur.com/KMMku.png <input id="wsUpload1" type= ...

How can you traverse through CSS page numbers using Python?

Is there a way to create a loop that iterates through page numbers for aria-label? browser.find_element_by_css_selector('[aria-label="Page 1"').click() browser.find_element_by_css_selector('[aria-label="Page 2"').cli ...

Tips for iterating through both a list and dictionary simultaneously within a for loop at the template level in Django

Within my view.py, there is a function that retrieves two variables: a dictionary named ca and a list named categories: def eventcateg_detail(request): ca = EventTypeCategory.objects.values() categories =[] for i in range(0, len(ca)): p ...

Python version 3.6 is throwing an error in tkinter when it says that GROOVE is

Just a few minutes ago, the program below was working perfectly fine. But then I made a small change, ran the code, encountered an error which caused Spyder to crash. Now, it's unable to find Frame or Groove or some other element. Right now, it's ...

Utilize Tensorflow with GPU in Pycharm

I am seeking to set up Tensorflow GPU in Pycharm on my Windows 10 system with CUDA v11.1 and cuDNN v8.0.4. While exploring various resources, I came across guides like the ones listed below: Installation Guide 1 How to run Tensorflow GPU in Pycharm? To ...

What are the steps to implement OpenCV for a real-time application?

When it comes to real time systems, a quick and efficient platform is essential. I'm curious about which combination would be best for real time image processing: OpenCV-Python, OpenCV-MVStudio (C++), OpenCV-Matlab, or OpenCV-Java? I've heard abo ...

Encountering an error when trying to switch between tabs and close a tab in a window

Currently, my code is designed to perform a sequence of actions: open a window, navigate to a link on the page, extract some data from that page, and then close the tab. However, I am encountering an issue with closing the tab after completing these step ...

The system encountered an issue: org.openqa.selenium.os.ProcessUtils killWinProcess ERROR: The process stubbornly refused to terminate even after

Here is an example of a data-driven test in Java using Selenium: @Test(dataProvider="wordpressdata") public void logintowordpress(String username, String password) throws InterruptedException { System.setProperty("webdriver.chrome.driver", "D:\& ...

Selenium is having trouble locating the specified tag

Why is the Python code unable to find the <video> tag for this specific URL? The Chrome dev tools show that the tag exists. I've tried various waits but have had no luck. from selenium import webdriver from selenium.webdriver.common.by import B ...

Encountering a Broken Pipe Error when using Selenium in conjunction with the ChromeDriver

While attempting to scrape a website's index page and locate an element containing login text, I ran the following code: from selenium import webdriver import os chromedriver = "/usr/bin/chromedriver" os.environ["webdriver.chrome.driver"] = chromedr ...

Error in Odoo 14: The first item in the sequence was expected to be a string instance, but a boolean

I encountered an issue where I'm receiving the error message: "in _get_report_values map(lambda x: x.ref, docs.account_invoice_ids)) or ', '.join( TypeError: sequence item 0: expected str instance, bool found". data['test'] = docs. ...

Django's Secure User Authentication and Account Access

I need assistance creating a login function and authentication in the views.py file within def login(request). I am looking to authenticate a specific username and password from my model class "Signup". If anyone can provide guidance on how to accomplish t ...

Encountered a Python interpreter error when attempting to load a JSON file with the json.load() function

In the realm of Python programming, I have crafted this code to delve into a JSON file. import os import argparse import json import datetime ResultsJson = "sample.json" try: with open(ResultsJson, 'r') as j: jsonbuffer = json.loa ...

Having trouble removing the last 4 values from a list in Python, they are not being removed as expected

After updating the guest list and inviting everyone, I realized that I could only accommodate two people for dinner. guests = ['Abbas', 'Rafy', "sherry"] for i in range(0,3): print("Hi, I am inviting you to d ...

I experimented with List using the remove method, but the outcome displayed "none." What could I be overlooking in this scenario?

def remove_element_from_list(list_data, element_value): result = list_data.remove(element_value) return(result) def execute(): result=remove_element_from_list([1,2,3,4,5], 3) print(result) if __name__ == "__main__": execute() ...

Struggling to concentrate on a recently opened Selenium window

Having trouble focusing on a new window using Selenium and Java while running my application on Internet Explorer. The new window opens but I'm unable to interact with it. I've tried the following code: Set<String> allwindows = driver.getW ...

Python's Selenium 4 does not support the Edge headless option set to True, only to False

I am working on a function that extracts information from a specific webpage (; focusing on ratings). I have recently set up selenium 4 along with webdriver_manager to manage the drivers efficiently. However, I encountered an issue when utilizing the head ...

What is the best way to fill missing values with the average in a Python dataset?

https://i.stack.imgur.com/aVQeV.jpg]2]3 I am facing an issue while trying to convert float data for use in a decision tree. Every time I attempt to apply label encoder, I encounter an error stating that the argument must be a string or number. ...