Selecting local files using watir-webdriver

I am trying to automate the process of selecting a local file from an html page using watir-webdriver

I have the following html

<body>
<form method="post" action="upload" enctype="multipart/form-data">
test file to upload: <input type="file" name="file" size="60" id="test"/>
<input type="submit" value="Upload" name="upload" id="upload" />
</form>
</body>

I am trying to click input using idfrom testand set the path to the local file that I want to download using watir-webdriver.

I can use the following to click a button to open a selection window using

@browser.goto 'http://www.test.com'
@browser.button(:id => 'test').click

however, I am trying to use the following (from research, this seems correct, but does not work)

@browser.file_field(:name => 'file').set("C:\\path\\to\\test\\file\\validTest.xml")

leading to the following error

Watir::Exception::UnknownObjectException: unable to locate element, using {:name=>"file",    :tag_name=>"input", :type=>"file"}

attempt

@browser.button(:id => 'test').set("C:\\path\\to\\test\\file\\validTest.xml")

leads to the following error

NoMethodError: undefined method `set' for #<Watir::Button:0x3859920>

Can anyone help? I am trying to understand why the parameter is file_fieldnot working.

+4
3

:

@browser.file_field(:id,"upload").set("filepath")

, IE, , IEDriverServer_Win32_2.33.0, , .

+4

:

@browser.file_field(:id => 'test').set("C:\\path\\to\\test\\file\\validTest.xml")
+1

Try using this in the latest version of IEDriver. assign the path to the variable and then set it

filepath = "C:\\path\\to\\test\\file\\validTest.xml"
@browser.file_field(:id,"upload").set(filepath)
0
source

Source: https://habr.com/ru/post/1568215/


All Articles