简体   繁体   English

python selenium 附加文件,没有可交互的元素

[英]python selenium attach file, no elements to interact with

I'm trying to attach file using selenium but the web site does not have element to interact with.我正在尝试使用 selenium 附加文件,但 web 站点没有可交互的元素。 I tried sending keys to multiple elements in this code which are related to attachment but Selenium needs an element with a type="file" but in this case there is none.我尝试将密钥发送到此代码中与附件相关的多个元素,但 Selenium 需要一个 type="file" 的元素,但在这种情况下没有。 Website is also using javascript.网站也使用 javascript。 here is the code from website这是来自网站的代码

<div id="multiattaches" class="multiattaches">
    
           <div class="multiattaches__content multiattaches__content_hidden" id="attachesContent">
            <div class="multiattaches__title">Attached files</div>
            <div class="multiattaches__clear" id="attachesClearContent">Delete all</div>
            <ol class="multiattaches__list" id="attachesList">
                
            </ol>
        </div>
    <div id="newAttachesLink" class="multiattaches__button" title="Attach a file">
        <i class="multiattaches__icon_attach"></i><span class="multiattaches__button__text">Attach</span>
    </div>
    <div class="multiattaches__count-attaches multiattaches__count-attaches_hidden" id="attachesCount">
        Files: <span id="attachesCountValue">-1</span>
    </div>
    <p id="newAttaches_info" class="new-attaches__info">Attach up to 32 files maximum 16 Mb per upload&nbsp;(.zip .txt .log .mqh .ex5 .mq5 .mq4 .ex4 .mt5 .set .tpl .cl .py .sqlite .csv .ipynb .gif .png .jpg .jpeg)</p>
</div>

I can click on these 2 elements and upload dialog box will appear but I cannot send keys with the file I want to add, error appears that it is not possible to interact with these elements我可以单击这 2 个元素,然后会出现上传对话框,但我无法使用要添加的文件发送密钥,出现错误,无法与这些元素交互

        <i class="multiattaches__icon_attach"></i>
<span class="multiattaches__button__text">Attach</span>

Is it even possible to attach files using selenium in this case?在这种情况下,甚至可以使用 selenium 附加文件吗? If not is there a solution how to bypass this?如果没有,是否有解决方案如何绕过这个?

I manually disabled javascript for the page, refreshed it and tried clicking on attachment buttons, nothing happens(again confirming that it using js)我手动禁用了页面的 javascript,刷新它并尝试单击附件按钮,没有任何反应(再次确认它使用 js)

I'm don't understand much about javascript so this might be false but imo only way to add file in this case is to create and execute script that functions similar to original but instead of intercepting the file from dialog box it would directly forward it.我对 javascript 不太了解,所以这可能是错误的,但在这种情况下,imo 添加文件的唯一方法是创建和执行功能类似于原始的脚本,而不是从对话框中截取文件,而是直接转发它. I just don't know how to do that.我只是不知道该怎么做。

Weird, now I see new line in code奇怪,现在我在代码中看到了新行

<div id="multiattaches" class="multiattaches">
    
           <div class="multiattaches__content multiattaches__content_hidden" id="attachesContent">
            <div class="multiattaches__title">Attached files</div>
            <div class="multiattaches__clear" id="attachesClearContent">Delete all</div>
            <ol class="multiattaches__list" id="attachesList" style="max-height: 376px;"><li id="at_1" class="multiattaches__item multiattaches__item_hidden"><input type="file" name="attachedFile" size="63" class="multiattaches__input" id="_1" accept=".zip,.txt,.log,.mqh,.ex5,.mq5,.mq4,.ex4,.mt5,.set,.tpl,.cl,.py,.sqlite,.csv,.ipynb,.gif,.png,.jpg,.jpeg"><div class="multiattaches__extension"></div><div class="multiattaches__desc"><div class="multiattaches__name"></div><div class="multiattaches__size"></div></div><div class="multiattaches__delete" title="delete" data-num="1"></div></li></ol>
        </div>
    <div id="newAttachesLink" class="multiattaches__button" title="Attach a file">
        <i class="multiattaches__icon_attach"></i><span class="multiattaches__button__text">Attach</span>
    </div>
    <div class="multiattaches__count-attaches multiattaches__count-attaches_hidden" id="attachesCount">
        Files: <span id="attachesCountValue">0</span>
    </div>
    <p id="newAttaches_info" class="new-attaches__info">Attach up to 32 files maximum 16 Mb per upload&nbsp;(.zip .txt .log .mqh .ex5 .mq5 .mq4 .ex4 .mt5 .set .tpl .cl .py .sqlite .csv .ipynb .gif .png .jpg .jpeg)</p>
</div>

This one这个

<li id="at_1" class="multiattaches__item multiattaches__item_hidden"><input type="file" name="attachedFile" size="63" class="multiattaches__input" id="_1" accept=".zip,.txt,.log,.mqh,.ex5,.mq5,.mq4,.ex4,.mt5,.set,.tpl,.cl,.py,.sqlite,.csv,.ipynb,.gif,.png,.jpg,.jpeg"><div class="multiattaches__extension"></div><div class="multiattaches__desc"><div class="multiattaches__name"></div><div class="multiattaches__size"></div></div><div class="multiattaches__delete" title="delete" data-num="1"></div></li>

And it contains the necesary element for selenium to work它包含 selenium 工作的必要元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium + Python - 无法与 JavaScript 交互/点击 - Selenium + Python - Not able to interact/click with JavaScript 如何使用Selenium与python中的javascript交互? - How to use Selenium to interact with javascript in python? 如何与 shadow DOM 元素交互以获取 file.pdf 和 selenium 4.x,使用 php 和 chrome 驱动程序 V95.0。? - how to interact with shadow DOM elements for take the file.pdf with selenium 4.x, using php and chrome driver V95.0.? 使用Selenium IDE与iframe元素进行交互的一种好方法是什么? - What is a good way to interact with iframe elements using Selenium IDE? 如何将文件对象附加到html元素? - How to attach file objects to html elements? 使用 selenium python 访问下拉元素 - Accessing dropdown elements with selenium python 通过 javascript 和 Python Selenium 获取元素 - Get elements by javascript with Python Selenium 如何将jQuery附加到Selenium的PhantomJS驱动程序(Python绑定) - How to attach jQuery to the PhantomJS driver of Selenium (Python bindings) 与div后面的元素进行交互 - Interact with elements behind a div 将jquery事件附加到动态创建的元素(jquery加载php文件) - Attach jquery events to dynamically created elements (jquery load php file)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM