I am creating a webscraper and the idea is to use Selenium, Robocorp and VSCode altogether.
I understand that Robocorp already has a file YAML that contains de dependencies of the code, but my doubt is, can I simply PIP INSTALL RPA.core.webdriver?
In my code , there is:
from RPA.core.webdriver import cache, download, start
and then:
def set_webdriver(self, browser="Chrome"):
options = self.set_chrome_options()
executable_driver_path = cache(browser)
if not executable_driver_path:
executable_driver_path = download(browser)
self.logger.warning("Using downloaded driver: %s" % executable_driver_path)
else:
self.logger.warning("Using cached driver: %s" % executable_driver_path)
self.driver = start("Chrome", executable_path=str(executable_driver_path), options=options)
Since then the error appears. How can I solve this, with conda.yaml?
# For more details on the format and content:
# https://github.com/robocorp/rcc/blob/master/docs/recipes.md#what-is-in-condayaml
# Tip: Adding a link to the release notes of the packages helps maintenance and security.
channels:
- conda-forge
dependencies:
- python=3.10.12 # https://pyreadiness.org/3.10
- pip=23.2.1 # https://pip.pypa.io/en/stable/news
- robocorp-truststore=0.8.0 # https://pypi.org/project/robocorp-truststore/
- nodejs=16.20.2 # https://github.com/nodejs/node/blob/main/CHANGELOG.md
- pip:
- robotframework-browser==17.5.2 # https://github.com/MarketSquare/robotframework-browser/releases
- rpaframework==27.7.0 # https://rpaframework.org/releasenotes.html
rccPostInstall:
- rfbrowser init # Initialize Playwright
I tried to use a method that uses a dependency, that I have no idea if it's already in the code.
`ImportError: cannot import name 'cache' from 'RPA.core.webdriver`
UPDATE I managed to install conda into my machine, ran the conda.YAML, created a environment, but I still cannot import this RPA.core. Does it even exists anymore?
Well, it looks like this is a very old architecture used for Selenium. Now, the Chrome webdriver is automatically downloaded and there is no need to specify the path anymore. My current versions accept the following code:
from selenium.webdriver import ChromeOptions
from selenium import webdriver
class CustomSelenium:
def set_webdriver(self):
self._driver = webdriver.Chrome(options=self._options)
print("WebDriver initialized successfully.")
cs = CustomSelenium()