Forked from SarahElson/test_nosuchelement_google.py
Created
September 28, 2022 16:05
Star
You must be signed in to star a gist
How To Handle Errors and Exceptions In Selenium Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from selenium import webdriver | |
import sys | |
from selenium.webdriver.common.by import By | |
from selenium.common.exceptions import NoSuchElementException | |
# Desired Capabilities according to SELENIUM 4 | |
ch_capabilities = { | |
'LT:Options' : { | |
"user" : "<username>", | |
"accessKey" : "<accesskey>", | |
"build" : "NoSuchElementException Test on Chrome", | |
"name" : "NoSuchElementException Test on Chrome", | |
"platformName" : "Windows 10" | |
}, | |
"browserName" : "Chrome", | |
"browserVersion" : "102.0", | |
} | |
def test_lambdatest_nosuchelement(): | |
# LambdaTest Profile username | |
user_name = "<username>" | |
# LambdaTest Profile access_key | |
app_key = "<accesskey>" | |
# Remote Url to connect to our instance of LambdaTest | |
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub" | |
ch_driver = webdriver.Remote( | |
command_executor=remote_url, desired_capabilities = ch_capabilities) | |
ch_driver.get('https://www.lambdatest.com/selenium-playground/') | |
ch_driver.maximize_window() | |
# will find an element by its NAME property on the page and click it | |
ch_driver.find_element(By.CLASS_NAME, "p-10").click() | |
ch_driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment