简体   繁体   中英

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. 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. Website is also using 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

        <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? 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)

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM