使用python和Selenium Webdriver创建自动填充表格,但是我无法自动填充文本框

时间:2018-10-25 13:21:50

标签: python python-3.x selenium selenium-webdriver textbox

from selenium import webdriver  
import time
br = webdriver.Chrome()
br.get('https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp')  
login_form = br.find_element_by_link_text('CHALLAN NO./ITNS 281').click()  
radio = br.find_elements_by_css_selector("input[type='radio'][value='0021']") [0].click()  
tan = br.find_elements_by_css_selector("input[type='text'][name='TAN']")[0].click()  
time.sleep(2)  
tan.send_keys("something")

一切正常except send_keys

无法在文本字段中填写文本并得到错误

Attribute error: 'NoneType' object has no attribute 'send_keys' 

1 个答案:

答案 0 :(得分:4)

click()不返回任何值,您无法单击它。保留从find_element返回的元素,并使用它单击并发送密钥

tan = br.find_elements_by_css_selector("input[type='text'][name='TAN']")[0]
tan.click()
tan.send_keys("something")