Skip to content

Commit

Permalink
Merge pull request #106 from aleksandr-kotlyar/python-docs-and-exampl…
Browse files Browse the repository at this point in the history
…es-03-2023

DOCS: actualize examples for selenium 4 on python
  • Loading branch information
rkrupski authored Apr 21, 2023
2 parents 1eb46de + 32ce4b7 commit 495bb03
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
19 changes: 17 additions & 2 deletions docs/desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@ For now to drive the Chromium-based Opera you’ll need to use the `RemoteWebDri
## Creating an OperaDriver service

```python
# Create OperaDriver service:
# Create and start OperaDriver service:
from selenium.webdriver.chrome import service
webdriver_service = service.Service(opera_driver_exe_path,
port_on_which_service_will_be_running)
webdriver_service.start()
```
### Creating a remote webdriver for selenium 4

### Creating a remote webdriver
```python
# Create OperaDriver options:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = opera_exe_path
options.add_experimental_option('w3c', True)
```

```python
# Create remote webdriver
remote = webdriver.Remote(webdriver_service.service_url, options=options)
```

### Creating a remote webdriver for selenium 2, 3

```python
# Create remote webdriver:
Expand Down
5 changes: 4 additions & 1 deletion docs/python-setup-step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
## Run example

For Android use [pure Selenium](../examples/android.py) or [Appium](../examples/appium_simple.py).
Desktop example: [desktop.py](../examples/desktop.py).

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).

Desktop example for selenium 4: [desktop_selenium_4.x.py](../examples/desktop_selenium_4.x.py).

## Troubleshooting

Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/desktop_selenium_4.x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import time

from selenium import webdriver
from selenium.webdriver.chrome import service

from selenium.webdriver.common.by import By

webdriver_service = service.Service("path/to/operadriver")
webdriver_service.start()

options = webdriver.ChromeOptions()
options.binary_location = "path/to/operabrowser"
options.add_experimental_option('w3c', True)

driver = webdriver.Remote(webdriver_service.service_url, options=options)

driver.get('https://www.google.com/')
input_txt = driver.find_element(By.NAME, 'q')
input_txt.send_keys('operadriver\n')

time.sleep(5) # see the result
driver.quit()

0 comments on commit 495bb03

Please sign in to comment.