1

May I know, how to find the element for upload button and proceed it with a mouse click by the following HTML code below:

<div class="uploadImage-wrap">
      <!-- Comment Title -->
      <div class="uploadImageTitle-wrap">
          <h2>Upload Files</h2>
      </div>

      <div id="uploadImage-containerSEC-2">

             <div id="dropzoneplaceSEC-2" class="dz-message">

                <div class="needsclick">
                <i class="fa fa-upload" aria-hidden="true"></i></br>
                Drop files here to upload.<br> or browse for a file

              </div>        
            </div>
           <input name="userFileName" type="hidden" value=""  id="userFileNameSEC-2">
           <input name="issueKey" type="hidden" value=""  id="issueKeySEC-2">
          <a href="#"><button type="button" id="uploadImageButtonSEC-2" class="btn blue changeBtn display-none" style='margin-left:40%;' onclick="addAttachmentForIssue(this)">Upload</button></a>

     </div>
</div><br/>

6
  • It has an id. What exactly is problem? Commented Jul 30, 2018 at 4:36
  • is say element not found when i wrote the this code driver.FindElement(By.Id("dropzoneplaceSEC-2")); js.ExecuteScript("arguments[0].scrollIntoView();", Element); driver.FindElement(By.Id("uploadImageButtonSEC-2")).Click(); Commented Jul 30, 2018 at 4:41
  • Try adding some wait stackoverflow.com/questions/25374382/… Commented Jul 30, 2018 at 4:47
  • 2
    This button has class display-none, probably it is invisible. Are you sure that is the button you really want to click? Commented Jul 30, 2018 at 4:56
  • driver.FindElement works for visible items only meaning they should be visible and not covered by other elements Commented Jul 30, 2018 at 5:39

1 Answer 1

2

According your comment:

yup i wanna click the button as once i uploaded the image the upload button only appear. how can i do that?

you have to use WebDriverWait to wait until element will be clickable:

// after you have uploaded an image
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("uploadImageButtonSEC-2")));
clickableElement.click();

this will wait at least 1 minute until element will be clickable and only then clicks on it.

Note: if your id is generic, you can use xPath to locate it:

//button[starts-with(@id, 'uploadImageButton')]

and code:

// after you have uploaded an image
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Xpath("//button[starts-with(@id, 'uploadImageButton')]")));
clickableElement.click();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.