Hello...
Here is my code runnung in pycharm
test_login.py
import time
from testcases.testresourses.applicationkeyword import applicationkeywords
app = applicationkeywords()
def test_login():
app.openBrowser('chrome')
app.navigate("URL")
app.click("loginlink_xpath")
time.sleep(5)
app.type("usernametextbox_xpath","dsworldonlinemail@gmail.com")
app.click("nextbtn_xpath")
time.sleep(5)
app.type("passwordtextbox_xpath","123")
app.click("signIn_xpath")
generickeywords.py
from selenium import webdriver
from pyjavaproperties import Properties
class genkeywords:
def __init__(self):
self.prop = Properties()
propertiesFile = open("D:\\Kalpana\\learnbay_python\\pytest_training\\Datadrivenframework\\config.properties")
self.prop.load(propertiesFile)
self.prop.list()
def openBrowser(self,browsername):
if(browsername == 'chrome'):
path = "D:\\Kalpana\\selenium_web_drivers\\chromedriver_win32 (3)\\chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path)
def navigate(self,url):
URL = self.prop(url)
self.driver.get(URL)
def click(self,elementTobeClicked):
obj = self.prop(elementTobeClicked)
self.driver.find_element('xpath',obj).click()
def type(self,element,data):
obj = self.prop(element)
self.driver.find_element('xpath',obj).send_keys(data)
config.properties
URL=https://www.zoho.com/
loginlink_xpath=//a[text()='Sign in']
usernametextbox_xpath=//*[@id='login_id']
nextbtn_xpath=//*[@id='nextbtn']
passwordtextbox_xpath=//*[@id='password']
signIn_xpath=//*[@id='nextbtn']
Issue is if i try to run test_login.py its giving following output but not opening the browser.
C:\Users\Ravi\AppData\Local\Programs\Python\Python37\python.exe -s D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py
-- listing properties --
URL=https://www.zoho.com/
loginlink_xpath=//a[text()='Sign in']
usernametextbox_xpath=//*[@id='login_id']
nextbtn_xpath=//*[@id='nextbtn']
passwordtextbox_xpath=//*[@id='password']
signIn_xpath=//*[@id='nextbtn']
If i call test_login() explicitly its just opening the browser but not the url and giving this error
Traceback (most recent call last):
File "D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py", line 25, in <module>
test_login()
File "D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py", line 6, in test_login
app.navigate("URL")
File "D:\Kalpana\learnbay_python\pytest_training\Datadrivenframework\testcases\testresourses\generickeywords.py", line 17, in navigate
URL = self.prop(url)
TypeError: 'Properties' object is not callable
I am not able to figure out where the code is failing. please suggest
And if i try to download the code its showing virus detected and closing abruptly. Please address this also.
Thank you
Kalpana
Getting one more issue after improvising
from _overlapped import NULL
from selenium import webdriver
from pyjavaproperties import Properties
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
class genkeywords:
def __init__(self):
self.prop = Properties()
propertiesFile = open("D:\\Kalpana\\learnbay_python\\pytest_training\\Datadrivenframework\\config.properties")
self.prop.load(propertiesFile)
self.prop.list()
def openBrowser(self,browsername):
if(browsername == 'chrome'):
path = "D:\\Kalpana\\selenium_web_drivers\\chromedriver_win32 (3)\\chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path)
print("Opening Browser")
def navigate(self,url):
URL = self.prop[url]
print("opening url ")
self.driver.get(URL)
def click(self,locatorKey):
self.getElement(locatorKey).click()
print("Clicking text box ")
def type(self,locatorKey,data):
self.getElement(locatorKey).send_keys(data)
print("Sending data ")
def isElementPresent(self,locatorKey):
wait = WebDriverWait(self.driver,20)
elementList = []
obj = self.prop[locatorKey]
if (locatorKey.endswith("_xpath")):
elementList = wait.until(EC.presence_of_all_elements_located((By.XPATH, obj)))
elif (locatorKey.endswith("_name")):
elementList = wait.until(EC.presence_of_all_elements_located((By.NAME, obj)))
elif (locatorKey.endswith("_id")):
elementList = wait.until(EC.presence_of_all_elements_located((By.ID, obj)))
else:
elementList = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, obj)))
if (len(elementList)==0):
return False
else:
return True
def isElementVisible(self,locatorKey):
wait = WebDriverWait(self.driver,20)
elementList = []
obj = self.prop[locatorKey]
if (locatorKey.endswith("_xpath")):
elementList = wait.until(EC.visibility_of_all_elements_located((By.XPATH, obj)))
elif (locatorKey.endswith("_name")):
elementList = wait.until(EC.visibility_of_all_elements_located((By.NAME, obj)))
elif (locatorKey.endswith("_id")):
elementList = wait.until(EC.visibility_of_all_elements_located((By.ID, obj)))
else:
elementList = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, obj)))
if (len(elementList)==0):
return False
else:
return True
def getElement(self, locatorKey):
obj = self.prop[locatorKey]
element = NULL
if (self.isElementPresent(locatorKey) and self.isElementVisible(locatorKey)):
try:
if (locatorKey.endswith("_xpath")):
element = self.driver.find_element('xpath', obj)
elif (locatorKey.endswith("_id")):
element = self.driver.find_element('id', obj)
elif (locatorKey.endswith("_name")):
element = self.driver.find_element('name', obj)
else:
element = self.driver.find_element('css_selector', obj)
return element
except Exception:
self.reportFailure("Element not found")
else:
self.reportFailure("Element not present/visible on webpage : " + locatorKey)
config.properties
URL=https://www.zoho.com/
loginlink_xpath=//a[text()='Sign in']
usernametextbox_id=login_id
nextbtn_xpath=//*[@id='nextbtn']
passwordtextbox_name=PASSWORD
signIn_xpath=//*[@id='nextbtn']
test_login.py
from testcases.testresourses.applicationkeyword import applicationkeywords
app = applicationkeywords()
def test_login():
app.openBrowser('chrome')
app.navigate("URL")
app.click("loginlink_xpath")
app.type("usernametextbox_id","dsworldonlinemail@gmail.com")
app.click("nextbtn_xpath")
app.type("passwordtextbox_name","learnabay123")
app.click("signIn_xpath")
test_login()
I am getting this error
C:\Users\Ravi\AppData\Local\Programs\Python\Python37\python.exe -s D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py
-- listing properties --
URL=https://www.zoho.com/
loginlink_xpath=//a[text()='Sign in']
usernametextbox_id=login_id
nextbtn_xpath=//*[@id='nextbtn']
passwordtextbox_name=PASSWORD
signIn_xpath=//*[@id='nextbtn']
Opening Browser
opening url
Clicking text box
Sending data
Traceback (most recent call last):
File "D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py", line 23, in <module>
test_login()
File "D:/Kalpana/learnbay_python/pytest_training/Datadrivenframework/testcases/test_login.py", line 9, in test_login
app.click("nextbtn_xpath")
File "D:\Kalpana\learnbay_python\pytest_training\Datadrivenframework\testcases\testresourses\generickeywords.py", line 31, in click
self.getElement(locatorKey).click()
File "D:\Kalpana\learnbay_python\pytest_training\Datadrivenframework\testcases\testresourses\generickeywords.py", line 77, in getElement
if (self.isElementPresent(locatorKey) and self.isElementVisible(locatorKey)):
File "D:\Kalpana\learnbay_python\pytest_training\Datadrivenframework\testcases\testresourses\generickeywords.py", line 61, in isElementVisible
elementList = wait.until(EC.visibility_of_all_elements_located((By.XPATH, obj)))
File "C:\Users\Ravi\AppData\Local\Programs\Python\Python37\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Process finished with exit code 1
My first issue of browser not opening without calling test_login() function is still existing.
Please suggest
Thank you
Hello....
My first issue is solved. But my second issue is still existing.
Could you suggest
Instructor
09914040666 Replied on 22/03/2021
Hey,
The xpath of nextbtn and signbtn are exactly the same because of which selenium is not able to extract the element. Change the xpath of one of them, try to make it more specific.
Hello..
Thank you for the reply.
I tried by changing next button locator to id. But getting the same exception again
FAILED [100%]Opening Browser
opening url
Clicking text box
Sending data
test_login.py:3 (test_login)
def test_login():
app.openBrowser('chrome')
app.navigate("URL")
app.click("loginlink_xpath")
app.type("usernametextbox_id","dsworldonlinemail@gmail.com")
> app.click("nextbtn_id")
test_login.py:9:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\testresourses\generickeywords.py:31: in click
self.getElement(locatorKey).click()
..\testresourses\generickeywords.py:77: in getElement
if (self.isElementPresent(locatorKey) and self.isElementVisible(locatorKey)):
..\testresourses\generickeywords.py:65: in isElementVisible
elementList = wait.until(EC.visibility_of_all_elements_located((By.ID, obj)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.support.wait.WebDriverWait (session="23c14e4363a18940b4ecc6a50e8c9fd5")>
method = <selenium.webdriver.support.expected_conditions.visibility_of_all_elements_located object at 0x00000267956F1E48>
message = ''
def until(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
screen = None
stacktrace = None
end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if value:
return value
except self._ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(self._poll)
if time.time() > end_time:
break
> raise TimeoutException(message, screen, stacktrace)
E selenium.common.exceptions.TimeoutException: Message:
C:\Users\Ravi\AppData\Local\Programs\Python\Python37\selenium\webdriver\support\wait.py:80: TimeoutException
Can you please suggest what changes can be done further.
Instructor
09914040666 Replied on 22/03/2021
Hey,
Kindly try these xpath:
nextBtn_xpath=//span[text()='Next']
signInBtn_xpath=//form[@id='login']//button[@id='nextbtn']
Instructor
09914040666 Replied on 23/03/2021
Thank you for the update.