Skip to content

Commit

Permalink
updata file_upload code (#1316)
Browse files Browse the repository at this point in the history
[deploy site]
  • Loading branch information
GavinHaydy committed Feb 27, 2023
1 parent fe4f33f commit 060f450
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,58 @@ namespace SeleniumDocumentation.SeleniumPRs
}

{{< /tab >}}
{{< tab header="Ruby" >}}
// Help us by sending a code sample for file upload

{{< 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" >}}
// Help us by sending a code sample for file upload
{{< /tab >}}
{{< tab header="Kotlin" >}}
// Help us by sending a code sample for file upload

{{< tab header="JavaScript" >}}
import {Builder,By} from "selenium-webdriver"


let driver = await new Builder().forBrowser('chrome').build()
await driver.get("https://the-internet.herokuapp.com/upload");

await driver.findElement(By.id("file-upload")).sendKeys("selenium-snapshot.jpg")
await driver.findElement(By.id("file-submit")).submit()

driver.getPageSource().then(result => {
if (result.indexOf("File Uploaded!")){
console.log("file upload success")
}else {
console.log("file upload not successful")
}
})

{{< /tab >}}

{{< tab header="Kotlin" >}}
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

fun main() {
val driver = ChromeDriver()
driver.get("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!")) {
println("file uploaded")
}
else{
println("file not uploaded")
}
}
{{< /tab >}}
{{< /tabpane >}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,60 @@ namespace SeleniumDocumentation.SeleniumPRs
}

{{< /tab >}}
{{< tab header="Ruby" >}}
// Help us by sending a code sample for file upload

{{< 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" >}}
// Help us by sending a code sample for file upload
{{< /tab >}}
{{< tab header="Kotlin" >}}
// Help us by sending a code sample for file upload

{{< tab header="JavaScript" >}}
import {Builder,By} from "selenium-webdriver"


let driver = await new Builder().forBrowser('chrome').build()
await driver.get("https://the-internet.herokuapp.com/upload");

await driver.findElement(By.id("file-upload")).sendKeys("selenium-snapshot.jpg")
await driver.findElement(By.id("file-submit")).submit()

driver.getPageSource().then(result => {
if (result.indexOf("File Uploaded!")){
console.log("file upload success")
}else {
console.log("file upload not successful")
}
})

{{< /tab >}}
{{< /tabpane >}}

{{< tab header="Kotlin" >}}
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

fun main() {
val driver = ChromeDriver()
driver.get("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!")) {
println("file uploaded")
}
else{
println("file not uploaded")
}
}
{{< /tab >}}
{{< /tabpane >}}

So the above example code helps to understand
how we can upload a file using Selenium.
how we can upload a file using Selenium.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ which we need to upload.
The code to upload the file for different programming
languages will be as follows -


{{< tabpane langEqualsHeader=true >}}
{{< tab header="Java" >}}
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -94,18 +93,60 @@ namespace SeleniumDocumentation.SeleniumPRs
}

{{< /tab >}}
{{< tab header="Ruby" >}}
// Help us by sending a code sample for file upload

{{< 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" >}}
// Help us by sending a code sample for file upload
{{< /tab >}}
{{< tab header="Kotlin" >}}
// Help us by sending a code sample for file upload

{{< tab header="JavaScript" >}}
import {Builder,By} from "selenium-webdriver"


let driver = await new Builder().forBrowser('chrome').build()
await driver.get("https://the-internet.herokuapp.com/upload");

await driver.findElement(By.id("file-upload")).sendKeys("selenium-snapshot.jpg")
await driver.findElement(By.id("file-submit")).submit()

driver.getPageSource().then(result => {
if (result.indexOf("File Uploaded!")){
console.log("file upload success")
}else {
console.log("file upload not successful")
}
})

{{< /tab >}}
{{< /tabpane >}}

{{< tab header="Kotlin" >}}
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

fun main() {
val driver = ChromeDriver()
driver.get("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!")) {
println("file uploaded")
}
else{
println("file not uploaded")
}
}
{{< /tab >}}
{{< /tabpane >}}

So the above example code helps to understand
how we can upload a file using Selenium.
how we can upload a file using Selenium.
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,60 @@ namespace SeleniumDocumentation.SeleniumPRs
}

{{< /tab >}}
{{< tab header="Ruby" >}}
// Help us by sending a code sample for file upload

{{< 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" >}}
// Help us by sending a code sample for file upload
{{< /tab >}}
{{< tab header="Kotlin" >}}
// Help us by sending a code sample for file upload

{{< tab header="JavaScript" >}}
import {Builder,By} from "selenium-webdriver"


let driver = await new Builder().forBrowser('chrome').build()
await driver.get("https://the-internet.herokuapp.com/upload");

await driver.findElement(By.id("file-upload")).sendKeys("selenium-snapshot.jpg")
await driver.findElement(By.id("file-submit")).submit()

driver.getPageSource().then(result => {
if (result.indexOf("File Uploaded!")){
console.log("file upload success")
}else {
console.log("file upload not successful")
}
})

{{< /tab >}}
{{< /tabpane >}}

{{< tab header="Kotlin" >}}
import org.openqa.selenium.By
import org.openqa.selenium.chrome.ChromeDriver

fun main() {
val driver = ChromeDriver()
driver.get("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!")) {
println("file uploaded")
}
else{
println("file not uploaded")
}
}
{{< /tab >}}
{{< /tabpane >}}

所以上面的示例代码有助于我们理解
如何使用Selenium上传文件.

0 comments on commit 060f450

Please sign in to comment.