简体   繁体   中英

Uploading a photo with Selenium WebDriver Java - css button

I have difficulties with uploading a file using a Selenium. I already read all the info in Stack Overflow, but nothing seems to work. I tried searching for the button or input using id/name/linkText/cssSelector/xPath, or even JavascriptExecutor. I then tried to click() it or sendKeys with a filepath, but nothing seems to work. When I click a button on the site I have a pop-up window, so wanted at least to make Selenium click it. Here is the site source. Obviously I'm not getting something here. What is wrong? How would you solve it? Thanks in advance.

<div id="image-uploader" class="btn primary">
     <form class="direct-upload" method="post" enctype="multipart/form-data" action="https://some_address">
         <input type="hidden" name="key">
         <input type="hidden" value="AKIAJCYVQEAJNT7OGZAQ" name="AWSAccessKeyId">
         <input type="hidden" value="public-read" name="acl">
         <input type="hidden" name="policy">
         <input type="hidden" name="signature">
         <input type="hidden" value="201" name="success_action_status">
         <input type="file" name="file" accept="image/*" style="top: 25.5px; left: 20.5px;">
         </form>
    Add Image
</div>

You would need to send keys to any node which has type=file. In your case, try using sendKeys to the below node -

<input type="file" name="file" accept="image/*" style="top: 25.5px; left: 20.5px;">

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