I'm trying to build a framework for test automation based on pytest_bdd. I'm able to perform many functionalities on my Social Networking Site where I'm performing my automation.
So, my use case is, after logging in, I need to search for a user and click on 'Add Friend' button. If manually I try to give specific xpath, I'm able to do that. But when I'm searching for multiple users having same name, say for example 'Nitin kumar', there are 2 users with same name. I want to add both of them as my friend, but I'm not able to click on them.
My steps are the following:
- Logging in
- Search for a user(Nitin kumar)
- Click on 'Add Friend' button - This is where I'm having problem
Necessary snippet from test_nitsanon.py
@when('the user clicks on add as friend besides a user')
def sendFrndReq(browser):
res, xp = clickBtn_multiple(browser, sendReq_addFrndBtn)
print('\n\n\n Sent Friend Request to all users with mentioned name >>> DEBUG\n', res, xp)
Snippet from functions.py
# Clicks a button on every iteration
def clickBtn_multiple(browser, xpath):
wait(3)
res = []
xp = []
s = browser.find_elements(By.XPATH, xpath)
for i in s:
res.append(i.text)
if xpath.is_displayed():
a = clickBy_Xpath(browser, xpath)
xp.append(a)
else:
continue
return res, xp
Snippet from xpaths.py
# Send friend request
sendReq_addFrndBtn = "//div[text()='" + sendReq_name + "']/ancestor::div/div/div/div/div/div[2]/child::div[2]/div/form/div/button"
Snippet from variables.py
nitsanonURL = "http://nitsanon.epizy.com/"
userValue = 'nitin'
passValue = 'kumar'
sendReq_name = "Nitin kumar"
What is wrong with this code? I guess there is something wrong with the function I've made! The return statement is returning an empty list. Check the output image here.