Posts

complete flow of shopping

  from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait chrome_options = Options() chrome_options.add_experimental_option( "detach" , True ) service_obj = Service( "C://Users//ancha//chromedriver_win32(4)//chromedriver.exe" ) driver = webdriver.Chrome( service =service_obj , options =chrome_options) driver.implicitly_wait( 4 ) driver.get( "https://rahulshettyacademy.com/angularpractice" ) driver.find_element(By.XPATH , "//a[contains(@href,'shop')]" ).click() products = driver.find_elements(By.XPATH , "//div[@class= 'card h-100']" ) for product in products: product_name = product.find_element(By.XPATH , "div/h4/a" ).text if product_name == "Blackberry"

For bypassing SSL and for running in headless mode

# for running in headless mode chrome_options = Options()   chrome_options.add_argument( "headless" ) driver = webdriver.Chrome( service =service_obj , options =chrome_options) #taking screenshot driver.get_screenshot_as_file("filename.png") # for bypassing SSL chrome_options = Options()   chrome_options.add_argument( "--ignore-certificate-errors" ) driver = webdriver.Chrome( service =service_obj , options =chrome_options)

Running javascript commands inside a python file through selenium

  from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service chrome_options = Options() chrome_options.add_experimental_option( "detach" , True ) service_obj= Service( "C://Users//ancha//chromedriver_win32(4)" ) driver = webdriver.Chrome( service =service_obj , options =chrome_options) driver.implicitly_wait( 2 ) driver.get( "https://rahulshettyacademy.com/AutomationPractice" ) driver.execute_script( "window.scrollBy(0,document.body.scrollHeight)" )

accessing frame through selenium and switching back to the original content

  from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.firefox.service import Service service_obj = Service( "C://Users//ancha//geckodriver-v0.33.0-win64//geckodriver.exe" ) driver = webdriver.Firefox( service = service_obj) driver.get( "http://the-internet.herokuapp.com/iframe" ) driver.switch_to.frame( "mce_0_ifr" ) driver.find_element(By.ID , "tinymce" ).clear() driver.find_element(By.ID , "tinymce" ).send_keys( "I am able to automate frame" ) driver.switch_to.default_content() print (driver.find_element(By.CSS_SELECTOR , "H3" ).text)

Getting email id from a child window and paste in parent window to login and catching the error message

  from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.firefox.service import Service from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait service_obj= Service( "C://Users//ancha//geckodriver-v0.33.0-win64//geckodriver.exe" ) driver= webdriver.Firefox( service =service_obj) driver.get( "http://www.rahulshettyacademy.com//loginpagePractise/" ) driver.find_element(By.CLASS_NAME , "blinkingText" ).click() windowsOpened = driver.window_handles driver.switch_to.window(windowsOpened[ 1 ]) driver.implicitly_wait( 2 ) message = driver.find_element(By.CSS_SELECTOR , ".red" ).text # var= message.slice(message,"at") print (message) var = message.split() # Variable containing the email em = "" print (var) for i in var: if "@" in i: em = i print (em) driver.close() driver.switch_to.window(windowsOpened[ 0 ]) d

Get the test from a child window and then switch back to parent window and check if the text is right

  from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.firefox.service import Service service_obj= Service( "C://Users//ancha//geckodriver-v0.33.0-win64//geckodriver.exe" ) driver= webdriver.Firefox( service =service_obj) driver.implicitly_wait( 2 ) #driver.get("http://www.google.com") driver.get( "http://the-internet.herokuapp.com/windows" ) driver.find_element(By.LINK_TEXT , "Click Here" ).click() windowsOpened= driver.window_handles driver.switch_to.window(windowsOpened[ 1 ]) print (driver.find_element(By.TAG_NAME , "h3" ).text) driver.close() driver.switch_to.window(windowsOpened[ 0 ]) assert driver.find_element(By.TAG_NAME , "h3" ).text == "Opening a new window"

Assert the expected names are displayed on the webpage for products

  import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait chrome_options = Options() #chrome_options = webdriver.ChromeOptions() chrome_options.add_argument( '--disable-web-security' ) chrome_options.add_experimental_option( "detach" , True ) exPdcts=[ "Cucumber - 1 Kg" , "Raspberry - 1/4 Kg" , "Strawberry - 1/4 Kg" ] actualList=[] service_obj= Service( "C://Users//ancha//chromedriver_win32(4)//chromedriver.exe" ) driver = webdriver.Chrome( service =service_obj , options =chrome_options) driver.implicitly_wait( 2 ) driver.get( "https://www.rahulshettyacademy.com/seleniumPractise" ) driver.find_element(By.CSS_SELECTOR , ".search-keyword" ).send_keys( "be