Feb-12-2018, 10:42 AM
hi,
I have a form whose html looks like this
what i am trying to do is select specific field from drop down in the form if it is equals to DEFAULT 1
now form is dynamic has only one thing common which is name "frm1"
but whenever i run my code i get error :
below are my codes
and th drop down i want to select whose html is like this:
i want to check if tower name is default 1 select drop mentioned in csv.
I have a form whose html looks like this
Quote:<form method="post" action="editTower" name="frm1" id="form0" onsubmit="return TOWERS.validateTowerForm(this);">
what i am trying to do is select specific field from drop down in the form if it is equals to DEFAULT 1
now form is dynamic has only one thing common which is name "frm1"
but whenever i run my code i get error :
Error:Traceback (most recent call last):
File "Z:\phase_tower_mapping\PHASE_ID_SELECTION.py", line 58, in <module>
form1 = div.find_element_by_name("frm1")#here find form by frm 1
AttributeError: 'list' object has no attribute 'find_element_by_name' below are my codes
from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.support.ui import Select
import time
#from bs4 import beautifulSoup
userid = "prince.bhatia"
password = "9811905164"
message = {}
filename = "./Book7.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:
continue
#print( val )
if val[1]=="" and val[2]=="" and val[3]=="":
continue
if len(val[0])>0:
prj = val[0]
print(prj)
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('http://newprojects.99acres.com/acd_99.php/mainpage/login')
email = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input")
email.send_keys("prince.bhatia")
password = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[3]/td[2]/input")
password.send_keys("9811905164")
l_button = driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td/table/tbody/tr[4]/td/input")
l_button.click()
url = "http://newprojects.99acres.com/index.php/miscellaneous/tower?rescom=R&projectid="
for pid in prj_structure.keys():# to access number 9
url1 = url+str(pid)
driver.get(url1)
total_elements = len( prj_structure[pid] )
for indx in range(total_elements):
ele = prj_structure[pid][indx]
i = str(indx+1)
div = driver.find_elements_by_tag_name("div")#form has all divs
form1 = div.find_element_by_name("frm1")#here find form by frm 1
for form in form1:
twr_nme = form[0].find_element_by_name("_edit_tower[TOWER_NAME]")#
#HERE IF TOWER NAME IS DEFAULT 1
for i in twr_nme:
txt = i.text
if txt.find("DEFAULT 1")!=-1:
lists = Select(driver.find_element_tag_name("_edit_tower[PHASEID]"))
lists.select_by_value(str(ele[2]))#HERE SELECT DROP DOWN FROM CSV
below html of tower name:Quote:<input name="_edit_tower[TOWER_NAME]" value="Default" size="10" class="tower_name_6151 __tower_name">
and th drop down i want to select whose html is like this:
Quote:<select name="_edit_tower[PHASEID]" class="phase_id">
<option value="224637">A Wing UC 2018-06-30</option>
<option value="314819" selected="selected">ARCHWAY UC 2018-12-29</option>
</select>
i want to check if tower name is default 1 select drop mentioned in csv.
