0

Hello Stackoverflow users!

I am trying to automate form submission using Powershell, and Selenium C# webdriver which i just started using a week ago.

As a basic example, I wanted to get all the values from A2 to C2 of an excel sheet below:

enter image description here

and put it into textboxes of a form, then submit it - as seen in this image:

enter image description here

Once it submits, it will then continue to the next row which is A3 to C3, and so on until there is no more value to read on.

So far, this is what i have:

POWERSHELL

$env:PATH += ";c:\selenium" # Adds the path for ChromeDriver.exe to the environmental variable 
Add-Type -Path "c:\selenium\WebDriver.dll" # Adding Selenium's .NET assembly (dll) to access it's classes in this PowerShell session
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$ChromeDriver.Url = 'c:\index.html'
$ChromeDriver.FindElementById('fruits').SendKeys('Apple');
$ChromeDriver.FindElementById('vegetables').SendKeys('Pechay');
$ChromeDriver.FindElementById('cars').SendKeys('Honda');
$ChromeDriver.FindElementById('submit').click();

HTML

  <input type="text" id="fruits" placeholder="Fruits"><br><br>
  <input type="text" id="vegetables" placeholder="Vegetables"><br><br>
  <input type="text" id="cars" name="cars" placeholder="Cars"><br><br>
  <input type="submit" id="submit" value="Submit">

I would greatly appreciate if someone can help, provide tips, or point me in the right direction.

Renz C. Gohing
  • 123
  • 1
  • 1
  • 9
  • Are you running into an error? If so, what is the error message and stack trace? – Greg Burghardt Mar 09 '21 at 18:45
  • No errors, but im struggling on how i would write the script to automatically submit the form without having to enter the value in the textboxes like this: $ChromeDriver.FindElementById('fruits').SendKeys('Apple'); I want to do it dynamically until there is no more data to read on in excel, maybe something like this would work but i am not sure: $ChromeDriver.FindElementById('fruits').SendKeys('$ExcelColumn1'); – Renz C. Gohing Mar 10 '21 at 10:28
  • We do not build solutions for people. Make an attempt to loop through the spreadsheet, and then update your question with a specific problem. As it stands right now, your question is little more than a proof of concept. We will not simply write the rest of the code for you. – Greg Burghardt Mar 10 '21 at 20:28
  • Ok, but i don't know where to start, would appreciate if you could provide at least a reference. – Renz C. Gohing Mar 14 '21 at 16:39
  • 1
    Does this answer your question? [Read Excel sheet in Powershell](https://stackoverflow.com/questions/19211632/read-excel-sheet-in-powershell) – Greg Burghardt Mar 18 '21 at 18:31

0 Answers0