DAY 9 - Web Automation Using Python Script
DAY 9 - Web Automation Using Python Script
Example 1: Login to Instagram
Step 1: Follow steps mentioned in DAY 1 - Blog to install library - selenium,xlrd,xlwings
https://dsbyrr.blogspot.com/2019/10/steps-to-prepare-your-windows-laptop.html
Step 2: Download Chrome driver from URL: https://chromedriver.storage.googleapis.com/index.html?path=78.0.3904.105/
Step 3: Create a file say Insta_login.py and save it at Desktop
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.action_chains import ActionChains
import xlrd
import xlwings as xw
try:
capabilities = {
'browserName': 'chrome',
'chromeOptions': {
'useAutomationExtension': False,
'forceDevToolsScreenshot': True,
'args': ['--start-maximized', '--disable-infobars']
}
}
# create a new Chrome session
driver = webdriver.Chrome(desired_capabilities=capabilities,
executable_path="C:/Users/Rakesh.Ranjan/Downloads/chromedriver_win32/chromedriver.exe") # path of chromedriver.exe
driver.implicitly_wait(30)
driver.maximize_window()
# Navigate to the application home page
insta_url = "https://www.instagram.com/accounts/login/?hl=en&source=auth_switcher"
driver.get(insta_url)
# get the User name textbox
user_name = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[2]/div/label/input')
user_name.clear()
user_name.send_keys(USER_NAME)
# get the Password textbox
# Password_id = driver.find_element_by_id("Password")
Password_id = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[3]/div/label/input')
Password_id.clear()
Password_id.send_keys(PASSWORD)
# enter submit
Password_id.submit()
except:
print('Unexpected error')
else:
print('Successful Login')
#RR #Day9 #Python #WebAutomationUsingPython #Selenium #HappyLearning #WeLearnEveryday
Example 1: Login to Instagram
Step 1: Follow steps mentioned in DAY 1 - Blog to install library - selenium,xlrd,xlwings
https://dsbyrr.blogspot.com/2019/10/steps-to-prepare-your-windows-laptop.html
Step 2: Download Chrome driver from URL: https://chromedriver.storage.googleapis.com/index.html?path=78.0.3904.105/
Step 3: Create a file say Insta_login.py and save it at Desktop
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.action_chains import ActionChains
import xlrd
import xlwings as xw
try:
capabilities = {
'browserName': 'chrome',
'chromeOptions': {
'useAutomationExtension': False,
'forceDevToolsScreenshot': True,
'args': ['--start-maximized', '--disable-infobars']
}
}
# create a new Chrome session
driver = webdriver.Chrome(desired_capabilities=capabilities,
executable_path="C:/Users/Rakesh.Ranjan/Downloads/chromedriver_win32/chromedriver.exe") # path of chromedriver.exe
driver.implicitly_wait(30)
driver.maximize_window()
# Navigate to the application home page
insta_url = "https://www.instagram.com/accounts/login/?hl=en&source=auth_switcher"
driver.get(insta_url)
# get the User name textbox
user_name = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[2]/div/label/input')
user_name.clear()
user_name.send_keys(USER_NAME)
# get the Password textbox
# Password_id = driver.find_element_by_id("Password")
Password_id = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[3]/div/label/input')
Password_id.clear()
Password_id.send_keys(PASSWORD)
# enter submit
Password_id.submit()
except:
print('Unexpected error')
else:
print('Successful Login')
#RR #Day9 #Python #WebAutomationUsingPython #Selenium #HappyLearning #WeLearnEveryday
Comments
Post a Comment