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

4

1 回答 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();
于 2018-07-30T06:27:21.597 回答