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 27, 2018 in Selenium by nitinrawat895
• 11,380 points
5,715 views

3 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 27, 2018 by nsv999
• 5,500 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, 2019 by anonymous
0 votes

You can try using Javascript Executor to run your file upload script onto webdriver as File Upload is an OS dialog box. Try using following command:

String script = "document.getElementById('fileName').value='" + "C:\\\\temp\\\\file.txt" + "';";
((IJavaScriptExecutor)driver).ExecuteScript(script);
answered Aug 23, 2019 by Abha
• 28,140 points

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,360 points
2,880 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,910 points
9,755 views
0 votes
2 answers

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

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
16,031 views
0 votes
5 answers
0 votes
2 answers

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,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,874 views
0 votes
1 answer
0 votes
2 answers

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

Hey, try using following code command to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
1,431 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP