Dec-28-2017, 08:14 AM
HI,
i am trying to fill the form using CSV file.
In this i have two queries , first i have to select radio button but it should match text from CSV file.
if text matches the condition it should select that radio button. First two radio button with the correct text matches properly but not the third one.
i am using this code to send dates
Please guide where i am wrong?
i am trying to fill the form using CSV file.
In this i have two queries , first i have to select radio button but it should match text from CSV file.
if text matches the condition it should select that radio button. First two radio button with the correct text matches properly but not the third one.
from selenium import webdriver from selenium.webdriver.common import keys from selenium.webdriver.support.ui import Select import time import datetime import os import sys userid = "xxx" password = "xxx" filename = "./phase.csv" prj_structure = {} f = open(filename, "r") data = f.read() f.close() lst = data.split("\n") prj = "" for i in range(1, len(lst)): val = lst[i].split(",") if len(val)<2: break #print( val ) if val[1]=="" and val[2]=="" and val[3]: break if len(val[0])>0: prj = val[0] if prj!="": if prj not in prj_structure.keys(): prj_structure[prj] = [] prj_structure[prj].append([ val[1], val[2], val[3]]) #print( prj_structure ) driver = webdriver.Chrome("./chromedriver") driver.get('xxx') email = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input") email.send_keys("xxx") password = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[3]/td[2]/input") password.send_keys("xxx") l_button = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[4]/td/input") l_button.click() url = "xxx" for pid in prj_structure.keys():# to access number 9 url1 = url+str(pid) driver.get(url1) time.sleep(1) total_elements = len( prj_structure[pid] ) for indx in range(total_elements): ele = prj_structure[pid][indx] i = str(indx+1) form = driver.find_elements_by_id("addform") for data in form: phasename = data.find_element_by_id('phase_name') phasename.send_keys(str(ele[1])) if "uc".find(str(ele[2]))!=-1 or "under".find(str(ele[2]))!=-1: data.find_element_by_xpath("//input[@value='UC']").click() elif "new".find(str(ele[2]))!=-1 or "launch".find(str(ele[2]))!=-1: data.find_element_by_xpath("//input[@value='N']").click() elif "ready".find(str(ele[2]))!=-1 or "move".find(str(ele[2]))!=-1: data.find_element_by_xpath("//input[@value='R']").click() dates = data.find_elements_by_id("completion_dt") for date in dates: dt_obj = datetime.datetime.strptime(date, '%M/%d/%Y') dtobj = dt_obj.strftime("%Y-%M-%d") dtobj.send_keys(str(ele[3]))In this code the error comes in( if i enter uc or new in CSV column to match it selects that radio button perfectly but not the ready to move one)
elif "ready".find(str(ele[2]))!=-1 or "move".find(str(ele[2]))!=-1: data.find_element_by_xpath("//input[@value='R']").click()and the error is
Error:Traceback (most recent call last):
File "C:\Users\prince.bhatia\Desktop\phasecreation\Corrections.py", line 67, in <module>
data.find_element_by_xpath("//input[@value='R']").click()
File "C:\Users\prince.bhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 77, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\prince.bhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 493, in _execute
return self._parent.execute(command, params)
File "C:\Users\prince.bhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "C:\Users\prince.bhatia\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=63.0.3239.84)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7601 SP1 x86_64)
second is send dates using pythoni am using this code to send dates
dates = data.find_elements_by_id("completion_dt") for date in dates: dt_obj = datetime.datetime.strptime(date, '%M/%d/%Y') dtobj = dt_obj.strftime("%Y-%M-%d") dtobj.send_keys(str(ele[3]))but when i run the code with the above correct conditions i get this error:
Error:Traceback (most recent call last):
File "C:\Users\prince.bhatia\Desktop\phasecreation\Corrections.py", line 71, in <module>
dt_obj = datetime.datetime.strptime(date, '%M/%d/%Y')
TypeError: strptime() argument 1 must be str, not WebElement
i have attached the CSV file for your reference Please guide where i am wrong?
Attached Files