Converting SeleniumWire's undetected_chromedriver to use multi-threading in SeleniumBase. #2097
-
Hello, everyone. Please, I need help with this. I have a code that uses Seleniumwire uc WebDriver, and it runs normally when I execute it for just one link. However, when I attempt to run it with multiple links using threading, it generates a lot of errors related to proxies due to the libraries I heard that the best way to resolve these errors is to convert it to a Selenium-based solution. Can anyone please help me with how I can do that My Code
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
I just need some help with the '''initialize_driver()''' function and setting it up with SeleniumBase. Can anyone assist a fellow newbie here? |
Beta Was this translation helpful? Give feedback.
-
i tried this |
Beta Was this translation helpful? Give feedback.
-
If you're encountering issues with Selenium wire and need to use a proxy, you can solve it by following these steps:
Create an instance of the `Driver` class with the desired proxy settings. Replace `'username:password@ip:port'` with your actual proxy credentials and address:
```python
from seleniumbase import Driver
driver = Driver(uc=True, proxy='username:password@ip:port')
|
Beta Was this translation helpful? Give feedback.
-
If you're looking to run multi-threaded tests in UC Mode with a proxy, here's the scoop: Multi-threading in UC Mode is possible if you use You'll need to use command-line options for this format, eg Below is a sample run command: pytest --uc -n4
Here's a sample file that uses import pytest
@pytest.mark.parametrize("", [[]] * 4)
def test_multi_threaded(sb):
sb.driver.get("https://nowsecure.nl/#relax")
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=5.25)
sb.post_message("Selenium wasn't detected!", duration=2.8)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.fail('Selenium was detected! Try using: "pytest --uc"') Here's the output when running that file with pytest test_multi_uc.py --uc -n4
============================ test session starts =============================
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
rootdir: ~/github/SeleniumBase/examples
configfile: pytest.ini
plugins: html-2.0.1, rerunfailures-12.0, cov-4.1.0, metadata-3.0.0, ordering-0.6, xdist-3.3.1, seleniumbase-4.17.13
4 workers [4 items]
Success! Website did not detect Selenium!
Success! Website did not detect Selenium!
..
Success! Website did not detect Selenium!
.
Success! Website did not detect Selenium!
.
============================= 4 passed in 9.38s ============================== Some websites may block you if they detect multiple simultaneous connections like that. Be careful where you go. Note that there are different syntax formats. See: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md Also note that |
Beta Was this translation helpful? Give feedback.
If you're looking to run multi-threaded tests in UC Mode with a proxy, here's the scoop:
Multi-threading in UC Mode is possible if you use
pytest
multi-threading provided by pytest-xdist.You'll need to use command-line options for this format, eg
--uc
to activate UC Mode,-n4
(for 4 parallel processes, etc), and--proxy=user:pass@host:port
to set proxy settings.Below is a sample run command:
Here's a sample file that uses
@pytest.mark.parametrize()
to turn one test into four tests when run withpytest
: