Skip to content

Commit

Permalink
Add documentation for the remote webdriver examples
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 5, 2023
1 parent 064fc5f commit b5d877a
Show file tree
Hide file tree
Showing 8 changed files with 906 additions and 1,149 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,29 @@ aliases: [
]
---

The file upload dialog could be handled using Selenium,
when the input element is of type file.
An example of it, could be found on this
web page- https://the-internet.herokuapp.com/upload
We will require to have a file available with us,
which we need to upload.
The code to upload the file for different programming
languages will be as follows -


{{< tabpane langEqualsHeader=true >}}
{{< badge-examples >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L26-L27">}}
{{< /tab >}}
{{< tab header="Python" >}}
from selenium import webdriver
driver.implicitly_wait(10)
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(By.ID,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(By.ID,"file-submit").submit()
if(driver.page_source.find("File Uploaded!")):
print("file upload success")
else:
print("file upload not successful")
driver.quit()

{{< /tab >}}
{{< tab header="CSharp" >}}
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumDocumentation.SeleniumPRs
{
class FileUploadExample
{
static void Main(String[] args)
{
IWebDriver driver = new ChromeDriver();
try
{
// Navigate to Url
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/upload");
driver.FindElement(By.Id("file-upload")).SendKeys("selenium-snapshot.jpg");
driver.FindElement(By.Id("file-submit")).Submit();
if (driver.PageSource.Contains("File Uploaded!"))
{
Console.WriteLine("file uploaded");
}
else
{
Console.WriteLine("file not uploaded");
}
driver.Quit();

}

}
}

{{< /tab >}}
Because Selenium cannot interact with the file upload dialog, it provides a way
to upload files without opening the dialog. If the element is an `input` element with type `file`,
you can use the send keys method to send the full path to the file that will be uploaded.

{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L17-L19" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/elements/test_file_upload.py#L12-L14" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Elements/FileUploadTest.cs#L21-L23" >}}
{{< /tab >}}
{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(:id,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(:id,"file-submit").submit()

if driver.page_source().include? "File Uploaded!"
puts "file upload success"
else
puts "file upload not successful"
end

{{< /tab >}}

{{< tab header="JavaScript" text=true >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L22-L25">}}
{{< gh-codeblock path="examples/ruby/spec/elements/file_upload_spec.rb#L12-L14" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L24-L25">}}
{{< /tab >}}

{{< tab header="Kotlin" >}}
{{< badge-examples >}}
```java
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

Expand All @@ -105,8 +45,6 @@ fun main() {
println("file not uploaded")
}
}
```
{{< /tab >}}
{{< /tabpane >}}

So the above example code helps to understand
how we can upload a file using Selenium.
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,29 @@ aliases: [
---


The file upload dialog could be handled using Selenium,
when the input element is of type file.
An example of it, could be found on this
web page- https://the-internet.herokuapp.com/upload
We will require to have a file available with us,
which we need to upload.
The code to upload the file for different programming
languages will be as follows -
Because Selenium cannot interact with the file upload dialog, it provides a way
to upload files without opening the dialog. If the element is an `input` element with type `file`,
you can use the send keys method to send the full path to the file that will be uploaded.

{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L26-L27">}}
{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L17-L19" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/elements/test_file_upload.py#L12-L14" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Elements/FileUploadTest.cs#L21-L23" >}}
{{< /tab >}}
{{< tab header="Python" >}}
from selenium import webdriver
driver.implicitly_wait(10)
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(By.ID,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(By.ID,"file-submit").submit()
if(driver.page_source.find("File Uploaded!")):
print("file upload success")
else:
print("file upload not successful")
driver.quit()

{{< /tab >}}
{{< tab header="CSharp" >}}
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumDocumentation.SeleniumPRs
{
class FileUploadExample
{
static void Main(String[] args)
{
IWebDriver driver = new ChromeDriver();
try
{
// Navigate to Url
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/upload");
driver.FindElement(By.Id("file-upload")).SendKeys("selenium-snapshot.jpg");
driver.FindElement(By.Id("file-submit")).Submit();
if (driver.PageSource.Contains("File Uploaded!"))
{
Console.WriteLine("file uploaded");
}
else
{
Console.WriteLine("file not uploaded");
}
driver.Quit();

}

}
}

{{< /tab >}}

{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(:id,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(:id,"file-submit").submit()

if driver.page_source().include? "File Uploaded!"
puts "file upload success"
else
puts "file upload not successful"
end

{{< /tab >}}

{{< tab header="JavaScript" text=true >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L22-L25">}}
{{< gh-codeblock path="examples/ruby/spec/elements/file_upload_spec.rb#L12-L14" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L24-L25">}}
{{< /tab >}}

{{< tab header="Kotlin" >}}
{{< badge-examples >}}
```java
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

Expand All @@ -104,8 +46,6 @@ fun main() {
println("file not uploaded")
}
}
```
{{< /tab >}}
{{< /tabpane >}}

So the above example code helps to understand
how we can upload a file using Selenium.
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,29 @@ description: >
---

A caixa de diálogo para o envio de arquivos pode ser tratada com o Selenium, quando o elemento de entrada é do tipo "file".
Pode observar um exemplo neste link https://the-internet.herokuapp.com/upload .
Because Selenium cannot interact with the file upload dialog, it provides a way
to upload files without opening the dialog. If the element is an `input` element with type `file`,
you can use the send keys method to send the full path to the file that will be uploaded.

Será necessário ter o arquivo a subir disponível para a operação.
Apresentamos alguns exemplos de código para subir os arquivos em diversas linguagens de programação:


{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" text=true >}}
{{< gh-codeblock path="/examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L26-L27">}}
{{< tabpane text=true langEqualsHeader=true >}}
{{< tab header="Java" >}}
{{< gh-codeblock path="examples/java/src/test/java/dev/selenium/elements/FileUploadTest.java#L17-L19" >}}
{{< /tab >}}
{{% tab header="Python" %}}
{{< gh-codeblock path="examples/python/tests/elements/test_file_upload.py#L12-L14" >}}
{{% /tab %}}
{{< tab header="CSharp" >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Elements/FileUploadTest.cs#L21-L23" >}}
{{< /tab >}}
{{< tab header="Python" >}}
from selenium import webdriver
driver.implicitly_wait(10)
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(By.ID,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(By.ID,"file-submit").submit()
if(driver.page_source.find("File Uploaded!")):
print("file upload success")
else:
print("file upload not successful")
driver.quit()

{{< /tab >}}
{{< tab header="CSharp" >}}
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumDocumentation.SeleniumPRs
{
class FileUploadExample
{
static void Main(String[] args)
{
IWebDriver driver = new ChromeDriver();
try
{
// Navigate to Url
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/upload");
driver.FindElement(By.Id("file-upload")).SendKeys("selenium-snapshot.jpg");
driver.FindElement(By.Id("file-submit")).Submit();
if (driver.PageSource.Contains("File Uploaded!"))
{
Console.WriteLine("file uploaded");
}
else
{
Console.WriteLine("file not uploaded");
}
driver.Quit();

}

}
}

{{< /tab >}}

{{< tab header="Ruby" >}}
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.get("https://the-internet.herokuapp.com/upload")
driver.find_element(:id,"file-upload").send_keys("selenium-snapshot.jpg")
driver.find_element(:id,"file-submit").submit()

if driver.page_source().include? "File Uploaded!"
puts "file upload success"
else
puts "file upload not successful"
end

{{< /tab >}}

{{< tab header="JavaScript" text=true >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L22-L25">}}
{{< gh-codeblock path="examples/ruby/spec/elements/file_upload_spec.rb#L12-L14" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
{{< gh-codeblock path="/examples/javascript/test/elements/fileUpload.spec.js#L24-L25">}}
{{< /tab >}}

{{< tab header="Kotlin" >}}
{{< badge-examples >}}
```java
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

Expand All @@ -104,7 +48,6 @@ fun main() {
println("file not uploaded")
}
}
```
{{< /tab >}}
{{< /tabpane >}}

Esperamos que estes exemplos de código possam ajudar a compreender como subir um arquivo com Selenium.
Loading

0 comments on commit b5d877a

Please sign in to comment.