1

I have a scenario where I will open my website and than I have to call the Rest API where in that API I will be needing some data, like user name,password and some URLs. The purpose of calling API is that I dont know the credentials as well as the URLS which is going to get check and every time these data will get change therefore I will just call an API. Below is my Selenium Python

from selenium import webdriver
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# declare variable to store the URL to be visited
base_url="https://www.fitotouch.com/qitouch"

driver = webdriver.Chrome('E:/Chrome driver/chromedriver.exe')
driver.maximize_window()
#function of our 'driver' object.
driver.implicitly_wait(10) #10 is in seconds
driver.get(base_url)
driver.implicitly_wait(10)
driver.find_element_by_name('password').send_keys("*****")
driver.implicitly_wait(10)
driver.find_element_by_class_name('arrow-icon').click()

After above click command I have to call API and Login from the data given in the API.

My API is : http://110.93.230.117:1403/api/order/5e439b7052fcf2189ccb5207

If I can get solution in Java than also it is Fine.

enter image description here

1 Answer 1

2

Use requests module to get the data as dictionary, from there you can get the values by the key

import requests

data = requests.get('http://110.93.230.117:1403/api/order/5e439b7052fcf2189ccb5207').json()
print(data)

"""
{'date': '2020-02-12T06:30:08.106Z',
 '_id': '5e439b7052fcf2189ccb5207',
 'fitoName': 'Chinasor 01 - Bu Yang Huan Wu Wan',
 'fitoCode': 'Chinasor 01',
 'providerName': 'Soria - Chinasor',
 'providerCode': 'Chinasor 01',
 'valueItem': '01',
 'Email': '[email protected]',
 '__v': 0}
"""
Sign up to request clarification or add additional context in comments.

4 Comments

Thank but now how I will use data in the API in my selenium? Means now I have given the xpath of Email and the email is present in the API.
@Maham Do you mean you want the value of Email? '[email protected]'? You can get the value by key data['Email'].
How I will locate email field. I have tried many ways but every time I am receiving an exception of unable to locate element. Screen shot is attached.
@Maham This is a new question, please raise one with the relevant code and html as text. But first try waiting for it stackoverflow.com/questions/32398859/… and check it's not inside iframe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.