Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的While循环,在读取文件时显示下一个单词的值_Python_Python 2.7_Selenium_If Statement_While Loop - Fatal编程技术网

python中的While循环,在读取文件时显示下一个单词的值

python中的While循环,在读取文件时显示下一个单词的值,python,python-2.7,selenium,if-statement,while-loop,Python,Python 2.7,Selenium,If Statement,While Loop,我制作了一个基于selenium的python程序,它插入了一些数据,如果一组特定的输入是正确的,它将返回它的值,但是如果正确的值是设为2,那么它将给出下一行作为它的输出,如3 我正在使用selenium在web表单中插入值,如果登录详细信息正确,它应该返回我的登录详细信息(它是我自己的web表单),在这种情况下,它是1-10之间的用户名,但是如果详细信息与用户名2匹配,它将再次读取文件,并显示为用户名3 f = open('a.txt', 'r') line=f.readline().str

我制作了一个基于selenium的python程序,它插入了一些数据,如果一组特定的输入是正确的,它将返回它的值,但是如果正确的值是设为2,那么它将给出下一行作为它的输出,如3 我正在使用selenium在web表单中插入值,如果登录详细信息正确,它应该返回我的登录详细信息(它是我自己的web表单),在这种情况下,它是1-10之间的用户名,但是如果详细信息与用户名2匹配,它将再次读取文件,并显示为用户名3

f = open('a.txt', 'r') 
line=f.readline().strip()
while line :
    line=f.readline().strip()
    print 'inserting username' , line


    if ('Profile Information' in driver.page_source):
        count = 1
        print 'username is ' , line
        break
    if ('An error occurred while processing your request.' in driver.page_source):
          print 'LookS like server time out or webpage has been inserted with a character waiting for 10 sec'
          time.sleep(10)
          driver.get(url)

driver.find_element_by_id("Fno").clear()
driver.find_element_by_id("Fno").send_keys('18047476')
driver.find_element_by_id("DOB").clear()
driver.find_element_by_id("DOB").send_keys(line)
driver.find_element_by_link_text("Login").click()
这是输出

insering username 1
insering username 2 

username is = 3

我已经编辑过了,但现在我觉得您有缩进问题,因为用户名打印无法通过缩进代码的方式访问。你能修好缩进吗?代码是哪里产生的?代码>插入…<代码>行。刚刚开始学习Python 2天,我知道C++,所以我有一个问题,压痕和所有,我只是不知道如何使用缩进。你是什么意思你不懂如何使用缩进?你使用什么文本编辑器?我只使用Python IDE作为Windows,就像C++一样,我们有{}来关闭循环,我们已经拥有了;对于结束语句,我不知道所有这些在python中的等价物,我切换到python,因为我需要使用selenium