Showing posts with label Python Selenium. Show all posts
Showing posts with label Python Selenium. Show all posts

Monday, July 8, 2019

Program to Fetch Alert count and Send Email

Program to Fetch Alert count and Send Email

Step used to Fetch alert count and send email to admin user accordingly
1.Open IBM Sterling WMS
2. Login into the System
3. Open Alert console
4. Input Username to search
5. Click Search button
6. Fetch No. of alerts to user
7. If count greater than 0, Send email with number of alerts
8. If count 0, Send email with no alerts

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import urllib.parse as urlparse
import pyautogui, time
import smtplib

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
time.sleep(0)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("testuser")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("testuser")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()
time.sleep(1)

#Open Alert Console
adjust="http://localhost:7001/smcfs/console/exception.search"
driver.get(adjust)
time.sleep(1)

#Input - Username to whom the Alerts assigned
driver.find_element_by_name("xml:/Inbox/User/@Loginid").send_keys("mano")
driver.find_element_by_name("btnSearch").click()
time.sleep(1)

#Obtaining value from Retrived records count
records=driver.execute_script("return document.all['TotalNumRecs'].value")
recordCount=int(records)
if recordCount>0:    
    FROM="FROMUSER@gmail.com"
    TO = "TOUSER@gmail.com"
    SUBJECT = "Alert Count"
    TEXT = "Hi Team, \n\nThere are "+records+" alerts to be closed. \n\nRegards\nAutomated Selenium Python Alert Team"
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.login("USERNAME", "PASSWORD")
    server.sendmail(FROM, TO, message)
    server.quit()
else:
    FROM = "FROMUSER@gmail.com"
    TO = "TOUSER@gmail.com"
    SUBJECT = "Alert Count"
    TEXT = "Hi Team, \n\nThere are no alert right now. \n\nRegards\nAutomated Selenium Python Alert Team"
    message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.login("USERNAME", "PASSWORD")
    server.sendmail(FROM, TO, message)
    server.quit()


Program to Open Calculator and read file for the Inputs

Program to Open Calculator and read file for the Inputs
Using Selenium Python

........ calculator_using_readfile.py ......................


import subprocess
import pyautogui, time

#Read File
f = open("E:\\Mano\\Python Selenium\\calculator_input.txt", "r")
input1 = f.readline().strip("\n\r")
operator1 = f.readline().strip("\n\r")
input2 = f.readline().strip("\n\r")
operator2 = f.readline().strip("\n\r")

#Open Calculator
subprocess.Popen('C:\\Windows\\System32\\calc.exe')
time.sleep(5)

#Value 5 pressed
pyautogui.press(input1)

#Operator x  pressed
pyautogui.press(operator1)

#Value 6 pressed
pyautogui.press(input2)

#Operator ENTER pressed
pyautogui.press(operator2)

## Total 5 x 6 => 30

........ calculator_input.txt ......................

#Below inputs in separate line
5
*
6
enter

Open Calculator using Selenium Python in Windows Machine

import subprocess

#Open Calculator
subprocess.Popen('C:\\Windows\\System32\\calc.exe')


Open MS Work using Selenium Python

import subprocess

#Loook in your system and mention path of MS Word EXE file
subprocess.Popen('C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE')



Perform Adjust Location Inventory using Selenium Python

Perform Adjust Location Inventory using Selenium Python

Steps perform below to Adjust Location Inventory:

1. Login into IBM Sterling
2. Open Location Inventory Console
3. Open Search Panel
4. Input ItemID in search panel
5. Click Search button
6. Click 4000-01 location from Search result
7. Select 1st record checkbox to Adjust inventory
8. Click AdjustLocationInventory button
9. Input ADJUSTMENT as ReasonCode
10. Select operation as Increase Inventory
11. Enter Quantity to increase as 10
12. Save the details
13. Close the poup window

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import pyautogui, time

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
#time.sleep(5)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("testuser")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("testuser")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()

time.sleep(3)

#Open Location Inventory Console
driver.get("http://localhost:7001/smcfs/console/wmsinventory.detail?yfcShowDetail=Y")

#Open Search Panel
driver.execute_script("slideSearchPanelView();")

# Set value to ItemID
driver.find_element_by_name("xml:yfcSearchCriteria:/NodeInventory/Inventory/InventoryItem/@ItemID").send_keys("XRXXFL2207")

# Click Search button
driver.find_element_by_xpath('//*[@name="btnSearch" and @type="submit"]').click()

# Click Location 4000-01 from Search result
continue_link = driver.find_element_by_link_text('4000-01').click()

# Select checkbox from search result
driver.find_element_by_xpath('//*[@name="chkEntityKey" and @type="checkbox" and @yHiddenInputName2="ItemKey_1"]').click()

# Click AdjustLocationInventory button
driver.find_element_by_id("scbutton2").click()

time.sleep(3)

# Use Pyautogui and enter reasonCode as ADJUSTMENT
pyautogui.press(['tab', 'tab', 'tab'])
pyautogui.typewrite('ADJUSTMENT')
pyautogui.press(['tab', 'tab', 'down', 'tab'])

# Use Pyautogui and enter quantity to increase as 10
pyautogui.typewrite('10')
time.sleep(5)

# Save the details
pyautogui.press(['tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'tab', 'enter'])
time.sleep(5)

# Close popup window
pyautogui.press(['tab', 'tab', 'enter'])

Program to login into IBM Sterling and identify number of alerts raised to given username.

Program to login into IBM Sterling and identify number of alerts raised to given username.

Steps used below:

1. Open IE browser
2. Login into IBM Sterling using username & password
3. Click login button
4. Open Alert Console screen
5. Input username in the Search box
6. Click the Search button
7. Fetch number of alerts


from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
time.sleep(1)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("testuser")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("testuser")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()
time.sleep(1)

#Open Alert Console
adjust="http://localhost:7001/smcfs/console/exception.search"
driver.get(adjust)
time.sleep(1)

#Input - Username to whom the Alerts assigned
driver.find_element_by_name("xml:/Inbox/User/@Loginid").send_keys("mano")
driver.find_element_by_name("btnSearch").click()
time.sleep(1)

#Obtaining value from Retrived records count
records=driver.execute_script("return document.all['TotalNumRecs'].value")
print(records)

Saturday, July 6, 2019

Basic operations in Selenium Python - Part #2

Basic operations in Selenium Python - Part #2

1. Click button using XPATH and selective attributes

# Identify the button using XPath and Attributes
driver.find_element_by_xpath('//*[@name="btnSearch" and @type="submit"]').click()

2. Delay in specific time


import time
....
....

# Delay the execution in 3 seconds as per below code
time.sleep(3)


3. Control using Keyboard character/button and Mouse controls using pyautogui

Reference:

import pyautogui
...
...

#Press TAB key
pyautogui.press('tab')

#Enter input using typewrite option. Example: ADJUSTMENT
pyautogui.typewrite('ADJUSTMENT')

#Press collective buttons using below way as well
pyautogui.press(['tab', 'tab', 'down', 'tab'])

#Press HOTKEYS using below logic.  i.e. ALT + F5
pyautogui.press(['alt', 'f5'])

4. Mouse Control using pyautogui


# Getting current mouse position
# X - X axis; Y - Y axis
(x, y) = pyautogui.position()
print(x,y)

# Move back to where the mouse was before click
# For Example: Application Configurator
pyautogui.moveTo(883, 182)

Basic operations in Selenium Python - Part 1

Basic operations in Selenium Python

1. Set value to input textbox

from selenium.webdriver.common.keys import Keys
....
....
# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("mano")

or 

# Set value to Username
driver.find_element_by_name("UserId").send_keys("mano")

2. Set value to input Dropdown or Select input

from selenium.webdriver.support.select import Select
....
....
#Set value to EnterpriseCode
#select by visible text i.e, MYENTS
selectEnterpriseCode = Select(driver.find_element_by_id('EnterpriseCode'))
selectEnterpriseCode.select_by_visible_text('MYENTS')

or 

#Set value to EnterpriseCode
#select by visible text i.e, MYENTS
Select(driver.find_element_by_id('EnterpriseCode')).select_by_visible_text('MYENTS')


3. Click anchor tag or hyperlink using link text

from selenium.webdriver.common.by import By
....
....

#Open Favorite link
driver.find_element_by_link_text('MyFavoriteShipments').click()

#Identify a hyperlink using its href SUBSTRING
#Then click the link
taskid = driver.find_element_by_xpath('//a[contains(@href, "%s")]' % "TaskKey")
taskid.click()


4. Execute script

#Call javascript method i.e, slideSearchPanelView()

driver.execute_script("slideSearchPanelView();")

#Get Dynamic Secure Token or get javascript variable's value
secureToken = driver.execute_script("return sc.csrf.value;")

Click hyperlink using Selenium Python in IBM Sterling WMS

Click hyperlink using Selenium Python in IBM Sterling WMS

Step used to achieve:


1. Open Internet Explorer Browser (IBM Sterling works fine in this Browser)
2. Open Login Screen
3. Input Username and Password to Login
4. Click Login form
5. Identify the hyperlink using link text and click it

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
import time

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
driver.fullscreen_window

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("xyz")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("abcd")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()

time.sleep(3)

#Open Favorite link
continue_link = driver.find_element_by_link_text('MyFavoriteShipments').click()

Step by Step guide to Install Selenium Python in Windows

Step by Step guide to Install Selenium Python in Windows


1. Download Python 3.7.0
    https://www.python.org/downloads/
    https://www.python.org/downloads/release/python-370/

2. To install
    use custom installation.
    select pip

3. once installation is complete navigate to the root folder
    (C:\Users\USERNAME\AppData\Local\Programs\Python\Python37)

4.  open the scripts folder and open cmd. Run belowcommand :
     pip install selenium

5.  Once it is done goto IE and click on settings>Internet Options>Security > Click on internet and the check mark on Enable protecttive mode. Similarly do this for local intranet, trusted sites and restricted sites.

6. Now navigate to http://selenium-release.storage.googleapis.com/index.html to download IE (Internet Explorer) Driver.
   i. Download 32 bit version of 2.39 (which is stable version; use 32 even if the system is 64bit).
   ii. Unzip the file and create a folder called Driver in any drive.
   iii. Right click on "This PC" and go to properties and then click on advance system settings.
   iv. Now click on Environmental variables and find "Path" in that and click on Edit.
   v. Click on New and add C:\Driver\
   vi. Save and exit

7. Open IDE and create new python script and run it.
8. Sample programs in 

Tuesday, July 2, 2019

Automate Inbound Shipment Confirmation in IBM Sterling using Selenium Python

Automate Inbound Shipment Confirmation in IBM Sterling using Selenium Python


In IBM Sterling WMS with version 9x.  Below Selenium script using Python code to Automate the Inbound Shipment Confirmation process.

Steps involved in Inbound Shipment Confirmation:

1. Open Internet Explorer Browser (IBM Sterling works fine in this Browser)
2. Open Login Screen
3. Input Username and Password to Login
4. Click Login form
5. Open Inbound Shipment Console (Out of the Box screen)
6. Input Seller, Buyer
7. Click "Create Shipment" button to Create the Shipment
8. Scroll down bit to Input Item Details to create Item into the Shipment
9. Input ItemID, ProductClass and Quantity
10. Save the Shipment
11. Confirm the Shipment

Selenium Python Code:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import time

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
#time.sleep(5)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("myusername")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("mypassword")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()

time.sleep(3)

#Open Inbound Shipment Console
driver.get("http://localhost:7001/smcfs/console/poshipment.detail?CurrentDetailViewID=YOMD7332")
driver.fullscreen_window

#Set Seller
setSeller  = driver.find_element_by_name("xml:/Shipment/@SellerOrganizationCode")
setSeller.send_keys("MODT")

#Set Buyer
setBuyer  = driver.find_element_by_name("xml:/Shipment/@BuyerOrganizationCode")
setBuyer.send_keys("KOMP")
time.sleep(3)

# Create Shipment
submitForm  = driver.find_element_by_xpath('//*[@type="button" and @class="button"]')
submitForm.click()
time.sleep(3)

# Scroll window
driver.execute_script("window.scrollTo(0, 200)")

#Add Item Details
driver.find_element_by_name("xml:/Shipment/ShipmentLines/ShipmentLine_1/@ItemID").send_keys("XXRXF00003")
Select(driver.find_element_by_name('xml:/Shipment/ShipmentLines/ShipmentLine_1/@ProductClass')).select_by_visible_text('Y001')
driver.find_element_by_name("xml:/Shipment/ShipmentLines/ShipmentLine_1/@Quantity").send_keys("10")

# Save Shipment
driver.find_element_by_xpath('//*[@type="button" and @class="button"]').click()
time.sleep(2)

# Confirm Shipment
driver.find_element_by_id("scbutton2").click()

Monday, July 1, 2019

Automate Login in IBM Sterling WMS using Selenium Python

In IBM Sterling WMS with version 9x.  Hope it will work for lower version too using below code.

After executing below code, it will automatically open Internet Explorer browser -> Open Sterling login screen (pls change URL for your code) -> Target Username field and set as anderson -> Target Password field and set as password and then click -> Submit button which will get logged in into the Sterling application.

1. Open Internet Explorer Browser (IBM Sterling works fine in this Browser)
2. Open Login Screen
3. Input Username and Password to Login
4. Click Login form

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
import time

driver = webdriver.Ie()
driver.get("http://localhost:7001/smcfs/console/login.jsp")
#time.sleep(5)

# Set value to Username
userName  = driver.find_element_by_name("UserId")
userName.send_keys("anderson")

# Set value to Password
passWord  = driver.find_element_by_name("Password")
passWord.send_keys("password")

# Submit the Form
submitForm  = driver.find_element_by_name("btnLogin")
submitForm.click()

Popular Posts