【问题标题】:How to upload files in selenium webdriver-python without input tag,Sendkeys如何在没有输入标签的情况下在 selenium webdriver-python 中上传文件,Sendkeys
【发布时间】:2019-07-13 11:06:33
【问题描述】:

我正在尝试发送 naver 电子邮件自动化 python 脚本,而我不能做的一件事是在没有 SendKeys 方法的情况下上传文件(甚至不必输入标签(元素)。我在谷歌搜索只有上传了一个带有输入标签的文件。请帮帮我。

我尝试通过 sendkeys 进行编码,但错误是 selenium.common.exceptions,ElementNotInteractableException: Message: element not interactable

    # Attachment 
    if attach:
    attach = config.attachment

    self.driver.find_element_by_xpath('//[@id="write_drag_here"]').send_keys('path in here')
    print('attachment activated')
    time.sleep(10)
    else:
    print('attachment deactivated')

我如何编码这个 HTML *HTML 代码:**

    <a href="#" id="AddButton_fla" class="utx_btn_b _c1(mwAttach|clickUpload) 
    _stopDefault" onclick="ccr(this,'wrh.attach',event)" style="display: none;"> 
    <span class="utx_inrbtn">내 PC</span></a>
    <a href="#" id="AddButton_html5" class="utx_btn_b 
    _click(mwAttach|clickHtml5Upload) _stopDefault" 
    onclick="ccr(this,'wh5.attach',event)" style="display: inline-block;">
    <span 
    class="utx_inrbtn">내 PC</span></a>

注意:如果您有什么不明白的地方,请随时再问我。

谢谢

【问题讨论】:

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


    【解决方案1】:

    如果脚本干扰它,我通常这样做的一种方法是使用屏幕坐标与元素交互,就像用户使用 AppRobotic 之类的宏程序一样,并模拟鼠标移动并仅在元素之后使用 SendKeys在屏幕上被激活:

    import win32com.client
    x = win32com.client.Dispatch("AppRobotic.API")
    from selenium import webdriver
    
    # navigate to Instagram
    driver = webdriver.Firefox()
    driver.get('https://www.AttachmentWebsite.com') 
    # sleep 1 second
    x.Wait(1000)
    
    # Move mouse to coordinates 250, 500 on the screen
    x.MoveCursor(250,500)
    x.MouseLeftClick
    # sleep 1 second
    x.Wait(1000)
    x.Type("my attachment")
    

    【讨论】:

      猜你喜欢
      • 2015-10-06
      • 2013-01-13
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2016-04-20
      相关资源
      最近更新 更多