Skip to content

Commit 32ce4b7

Browse files
DOCS: actualize examples for selenium 4 on python
1 parent 1eb46de commit 32ce4b7

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

Diff for: docs/desktop.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,28 @@ For now to drive the Chromium-based Opera you’ll need to use the `RemoteWebDri
55
## Creating an OperaDriver service
66

77
```python
8-
# Create OperaDriver service:
8+
# Create and start OperaDriver service:
99
from selenium.webdriver.chrome import service
1010
webdriver_service = service.Service(opera_driver_exe_path,
1111
port_on_which_service_will_be_running)
12+
webdriver_service.start()
1213
```
14+
### Creating a remote webdriver for selenium 4
1315

14-
### Creating a remote webdriver
16+
```python
17+
# Create OperaDriver options:
18+
from selenium import webdriver
19+
options = webdriver.ChromeOptions()
20+
options.binary_location = opera_exe_path
21+
options.add_experimental_option('w3c', True)
22+
```
23+
24+
```python
25+
# Create remote webdriver
26+
remote = webdriver.Remote(webdriver_service.service_url, options=options)
27+
```
28+
29+
### Creating a remote webdriver for selenium 2, 3
1530

1631
```python
1732
# Create remote webdriver:

Diff for: docs/python-setup-step-by-step.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
## Run example
3737

3838
For Android use [pure Selenium](../examples/android.py) or [Appium](../examples/appium_simple.py).
39-
Desktop example: [desktop.py](../examples/desktop.py).
39+
40+
Desktop example for selenium 2 and selenium 3: [desktop_selenium_2.x_and_3.x.py](../examples/desktop_selenium_2.x_and_3.x.py).
41+
42+
Desktop example for selenium 4: [desktop_selenium_4.x.py](../examples/desktop_selenium_4.x.py).
4043

4144
## Troubleshooting
4245

File renamed without changes.

Diff for: examples/desktop_selenium_4.x.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
3+
from selenium import webdriver
4+
from selenium.webdriver.chrome import service
5+
6+
from selenium.webdriver.common.by import By
7+
8+
webdriver_service = service.Service("path/to/operadriver")
9+
webdriver_service.start()
10+
11+
options = webdriver.ChromeOptions()
12+
options.binary_location = "path/to/operabrowser"
13+
options.add_experimental_option('w3c', True)
14+
15+
driver = webdriver.Remote(webdriver_service.service_url, options=options)
16+
17+
driver.get('https://www.google.com/')
18+
input_txt = driver.find_element(By.NAME, 'q')
19+
input_txt.send_keys('operadriver\n')
20+
21+
time.sleep(5) # see the result
22+
driver.quit()

0 commit comments

Comments
 (0)