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

Maham
  • 91
  • 1
  • 12

1 Answers1

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': 'helder@gmail.com',
 '__v': 0}
"""
Guy
  • 46,488
  • 10
  • 44
  • 88
  • 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 Mar 01 '20 at 09:37
  • @Maham Do you mean you want the value of `Email`? `'helder@gmail.com'`? You can get the value by key `data['Email']`. – Guy Mar 01 '20 at 09:39
  • 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 Mar 02 '20 at 11:06
  • @Maham This is a new question, please raise one with the relevant code and html as text. But first try waiting for it https://stackoverflow.com/questions/32398859/how-can-i-wait-for-an-element-will-be-visible-then-be-clicked-in-python-selenium and check it's not inside `iframe`. – Guy Mar 02 '20 at 11:19