51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1270|回复: 0

[selenium] 无法click的一个案例分享for selenium

[复制链接]
  • TA的每日心情
    无聊
    昨天 09:11
  • 签到天数: 932 天

    连续签到: 4 天

    [LV.10]测试总司令

    发表于 2022-9-29 14:25:14 | 显示全部楼层 |阅读模式
    点击网页的第一个选择文件,如图:

    示例代码
    1. <font size="3">  from selenium import webdriver  

    2.     

    3.    driver = webdriver.Chrome()  

    4.    driver.get('http://sahitest.com/demo/php/fileUpload.htm')  

    5.     

    6.    driver.find_element('id','file').click()</font>
    复制代码
    运行效果:报错了:invalid argument,无效的参数。
    1. <font size="3">D:\Python39\python.exe D:/pythonProject/deom1.py

    2.    Traceback (most recent call last):

    3.      File "D:\pythonProject\deom1.py", line 8, in <module>

    4.        driver.find_element('id','file').click()

    5.      File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 88, in click

    6.        self._execute(Command.CLICK_ELEMENT)

    7.      File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute

    8.        return self._parent.execute(command, params)

    9.      File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute

    10.        self.error_handler.check_response(response)

    11.      File "D:\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response

    12.        raise exception_class(message, screen, stacktrace)

    13.    selenium.common.exceptions.InvalidArgumentException: Message: invalid argument

    14.      (Session info: chrome=104.0.5112.81)

    15.    Stacktrace:

    16.    Backtrace:

    17.        Ordinal0 [0x004F5FD3+2187219]

    18.        Ordinal0 [0x0048E6D1+1763025]

    19.        Ordinal0 [0x003A3D40+802112]

    20.        Ordinal0 [0x003C9171+954737]

    21.        Ordinal0 [0x003ECB8C+1100684]

    22.        Ordinal0 [0x003C8394+951188]

    23.        Ordinal0 [0x003ECDA4+1101220]

    24.        Ordinal0 [0x003FCFC2+1167298]

    25.        Ordinal0 [0x003EC9A6+1100198]

    26.        Ordinal0 [0x003C6F80+946048]

    27.        Ordinal0 [0x003C7E76+949878]

    28.        GetHandleVerifier [0x007990C2+2721218]

    29.        GetHandleVerifier [0x0078AAF0+2662384]

    30.        GetHandleVerifier [0x0058137A+526458]

    31.        GetHandleVerifier [0x00580416+522518]

    32.        Ordinal0 [0x00494EAB+1789611]

    33.        Ordinal0 [0x004997A8+1808296]

    34.        Ordinal0 [0x00499895+1808533]

    35.        Ordinal0 [0x004A26C1+1844929]

    36.        BaseThreadInitThunk [0x7635FA29+25]

    37.        RtlGetAppContainerNamedObjectPath [0x773A7A9E+286]

    38.        RtlGetAppContainerNamedObjectPath [0x773A7A6E+238]

    39.     

    40.     

    41.    进程已结束,退出代码为 1</font>
    复制代码
    解决方法
      ·用鼠标方法

    1. <font size="3"> from selenium import webdriver  

    2.    from selenium.webdriver import ActionChains  

    3.      

    4.    driver = webdriver.Chrome()  

    5.    driver.get('http://sahitest.com/demo/php/fileUpload.htm')  

    6.    ele_fie = driver.find_element('id','file')  

    7.    ActionChains(driver).click(ele_fie).perform()</font>
    复制代码
    说明
      ·不是很好解释
      · 提交了问题到stackoverflow:https://stackoverflow.com/questi ... onchains-works-fine,看看有无大神帮忙解释下。
      参考答案

    1. <font size="3">In the DOM I see, the input element has attribute type=file, which means it is a file upload dialog that is related to OS and Selenium cannot perform operations on this one directly. Hence ActionChains.</font>
    复制代码
    翻译: 的确,在网页上,input标签是有这个属性的type=file,这是一个文件上传的对话框,跟OS相关,selenium无法对该元素直接执行操作,因此( )可以用ActionChains。

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    回复

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-4-19 01:09 , Processed in 0.078076 second(s), 24 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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