Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Edit Form using Selenium
#1
hi,

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.
Reply
#2
i dont have the cvs file to run your code. Are you able to upload it if your code requires it?

What is the set of actions you wish to take on this site?
Recommended Tutorials:
Reply
#3
The error message is very clear,and common using selenium.
Line 57 is a list.
>>> div = ['the stuff you want']
>>> div.find_element_by_name("frm1")
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
AttributeError: 'list' object has no attribute 'find_element_by_name
So to get what you want [0]
>>> div[0]
'the stuff you want'
form1 = div[0].find_element_by_name("frm1")#here find form by frm 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,135 Jan-09-2021, 06:08 PM
Last Post: eraosa
  Pre-populating WTForms form values for edit danfoster 0 2,351 Feb-25-2020, 01:37 PM
Last Post: danfoster
  Posting value from excel to Form (Python+Selenium) revanth 0 1,764 Feb-05-2020, 10:44 AM
Last Post: revanth
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,588 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020