
Creating a Automated script in Python
This is the starting of our Selenium automation with Python.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
driver = webdriver.Chrome(executable_path="E://python tutorial//selenium_demo//chromedriver.exe")
driver.get("http://demo.guru99.com/test/newtours/")
print(driver.title)
driver.close()
For executing this script you will be required to Install Python, Selenium and Visual Studio Code (you can also use Pycharm)
“driver = webdriver.Chrome(executable_path=”E://python tutorial//selenium_demo//chromedriver.exe”)”
Here in this step we are providing the path of our chromedriver.exe
“driver.get(“http://demo.guru99.com/test/newtours/”)”
The above step consist of get(), this method is responsible for opening the URL in Browser.
print(driver.title) By using this step you can easily print the title of your application in test.
Once the test is completed you can close the application by using driver.close()
sss@DESKTOP-915O4CC MINGW64 /e/python tutorial/selenium_demo
$ [11924:11424:0413/142136.932:ERROR:device_event_log_impl.cc(214)] [14:21:36.932] Bluetooth: bluetooth_adapter_winrt.cc:712 GetBluetoothAdapterStaticsActivationFactory failed: Class not registered (0x80040154)
[11924:11424:0413/142137.037:ERROR:device_event_log_impl.cc(214)] [14:21:37.036] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
python sampleTest01.py
DevTools listening on ws://127.0.0.1:55122/devtools/browser/65f31bf4-da7a-41a0-8743-8d9516859d7f
[1812:11504:0413/142151.565:ERROR:device_event_log_impl.cc(214)] [14:21:51.564] Bluetooth: bluetooth_adapter_winrt.cc:712 GetBluetoothAdapterStaticsActivationFactory failed: Class not registered (0x80040154)
[1812:11504:0413/142151.666:ERROR:device_event_log_impl.cc(214)] [14:21:51.666] USB: usb_device_handle_win.cc:1056 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Welcome: Mercury Tours
This is the Output for your test.