Trying to upload files using Selenium(C#)

0 votes

I am trying to Upload files by clicking on "Upload completed form". When I use XPath to locate it and click on it, nothing works. Is there a way out?

Below is the HTML from inspecting Chrome.

<button ng-if="$root.AccessLevel.Standard" class="btn btn--small btn--icon ng-pristine ng-valid ng-touched" ng-model="vm.uploads[workCategory.Id].reference" ngf-max-size="'5MB'" ngf-model-invalid="vm.uploads[workCategory.Id].referenceInvalid" ngf-pattern="'.pdf,.doc,.docx,.bmp,.gif,.jpg,.jpeg,.tif,.wmf,.png'" ngf-select="vm.uploadFile($file, 'WorkCategoryReference', workCategory.Id, workCategory.References, workCategory.Id+'uploadRef')">
    <span promise="vm.promises[workCategory.Id+'uploadRef']">
        <span ng-hide="pending" class="">
            <i class="fa fa-lg fa-cloud-upload"></i>
        </span>
        <span ng-show="pending" class="ng-hide">
            <i class="fa fa-lg fa-refresh fa-spin"></i>
        </span>
    </span>
    Upload completed form
</button>

Below is my NUnit class with the XPath passed in

wait.PathWaitAndClick(driver, "*[@id=\"accordiongroup - 299 - 4516 - panel\"]/div/div[2]/div[1]/table/tfoot/tr/td/button", 2000);

Also below I’m using WebExtension method.

public static void PathWaitAndClick(this WebDriverWait wait, IWebDriver driver, string path, int pause = 0)
{
    if (pause > 0)
    {
        System.Threading.Thread.Sleep(pause);
    }
    wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath(path)));
    IWebElement viewAllWc = driver.FindElement(By.XPath(path));
    if (pause > 0)
    {
        System.Threading.Thread.Sleep(pause);
    }
    viewAllWc.Click();
}
Mar 26, 2018 in Selenium by nitinrawat895
• 10,490 points
886 views

2 answers to this question.

0 votes
Well, I think the problem is with your XPath. You can check if your XPath is valid using the command $x("your xpath") at your chrome console. You can also check if it is inside an Iframe by checking the page's html. If the debugger can't reach your breakpoint to debug your clicking action, there is something else that is wrong. Are there errors in browser console? All these points can impact and result on a error in that line.
answered Mar 26, 2018 by nsv999
• 5,050 points
0 votes
For uploading file using C# we use the windows form like this below

using System.Windows.Forms;  //this add as a reference in your upper side display and in the class write code show  below

//for adding reference right click on reference file and  add reference system.window forms

Class A

{

//write the code for press key that is upload button

  SendKeys.SendWait("C:\\abc\\abc.txt");
            SendKeys.SendWait(@"{Enter}");

}
answered Feb 1 by anonymous

Related Questions In Selenium

0 votes
1 answer

How to upload a resume to a website using selenium in python?

Use this code, this will help you: from ...READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,250 points
1,036 views
0 votes
1 answer

How to control Chrome Downloads page Using Selenium c#?

In your case you must replace 'cancel' ...READ MORE

answered May 7, 2018 in Selenium by Samarpit
• 5,130 points
1,158 views
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
2,968 views
0 votes
2 answers
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
403 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
760 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
400 views
0 votes
1 answer
0 votes
1 answer

How can we take screenshots of tests in Selenium 2 using C#

We can take screenshots using below function ...READ MORE

answered Mar 23, 2018 in Selenium by nsv999
• 5,050 points
142 views