51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1952|回复: 8

Selenium Python 代码之打开网页自动填充内容并搜索

[复制链接]
  • TA的每日心情
    无聊
    前天 09:12
  • 签到天数: 918 天

    连续签到: 3 天

    [LV.10]测试总司令

    发表于 2020-9-2 11:30:50 | 显示全部楼层 |阅读模式
    Selenium Python 代码之打开网页自动填充内容并搜索流程1、通过id找到文本框
    1. inputElement.send_keys(Keys.BACK_SPACE )
    复制代码
    2、发送删除键,清除一下之前文字
    1. inputElement.send_keys(Keys.BACK_SPACE )
    复制代码
    3、发送需要查询对内容并送个回车
    1.        inputElement = driver1.find_element_by_id("TextBox1")  
    2.     inputElement.send_keys(w_str)
    3.     inputElement = driver1.find_element_by_id("TextBox1")  
    4.     inputElement.send_keys(Keys.ENTER)
    复制代码
    代码
    1. from selenium import webdriver
    2. from selenium.webdriver.common.keys import Keys

    3. def search(ele,w_str):
    4.     inputElement=ele
    5.     inputElement = driver1.find_element_by_id("TextBox1")  
    6.     inputElement.send_keys(Keys.BACK_SPACE )
    7.     inputElement = driver1.find_element_by_id("TextBox1")  
    8.     inputElement.send_keys(w_str)
    9.     inputElement = driver1.find_element_by_id("TextBox1")  
    10.     inputElement.send_keys(Keys.ENTER)
    11.    
    12. driver1= webdriver.Chrome()                                             
    13. url='http://www.guzicha.com'                             
    14. driver1.get(url)                                                        
    15. search(inputElement,'图')
    复制代码

    作者:LeepengX
    链接:https://www.jianshu.com/p/1dd1a878dfb7
    来源:简书

    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-3-29 08:44 , Processed in 0.065206 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表