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

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
Kevin
  • 147
  • 1
  • 1
  • 10
  • It has an `id`. What exactly is problem? – Guy Jul 30 '18 at 04: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(); – Kevin Jul 30 '18 at 04:41
  • Try adding some wait https://stackoverflow.com/questions/25374382/how-to-wait-for-element-to-load-in-selenium-webdriver/40397653 – Guy Jul 30 '18 at 04:47
  • 2
    This button has class `display-none`, probably it is invisible. Are you sure that is the button you really want to click? – Andrei Suvorkov Jul 30 '18 at 04:56
  • driver.FindElement works for visible items only meaning they should be visible and not covered by other elements – Sergey Prosin Jul 30 '18 at 05:39
  • @AndreiSuvorkov yup i wanna click the button as once i uploaded the image the upload button only appear. how can i do that? – Kevin Jul 30 '18 at 06:17

1 Answers1

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();
Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48