0

I need to click on the "Browse" button on the below webpage.

http://www.guru99.com/freelancing.html

I have written the below code but webdriver fails to find the Browse button element. Please help.

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class FileUpload {

    public static void main(String[] args) throws IOException {
        System.setProperty("webdriver.gecko.driver", "C:\\Eclipse\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.navigate().to("http://www.guru99.com/freelancing.html");
        driver.findElement(By.id("theFile_link(Resume)")).click();
        //Below line execute the AutoIT script
        Runtime.getRuntime().exec(System.getProperty("user.dir")+"\\FileUpload.exe");
        driver.close();
    }
}

I'm Using:

Firefox Version: 49.0.1

Selenium Version: Version 3.0.0-beta4

OS: Win10 64 bit

Java: 1.8

2
  • 1
    Update your ticket with exception log. Also let us know why you try to click that button and execute AutoIT script instead of just send path to file to //input[@id="theFile_property(Resume)_1"] Commented Oct 9, 2016 at 9:52
  • Could you share relevant HTML here as well Commented Oct 9, 2016 at 10:36

2 Answers 2

2

The form (and Browse button) is inside <iframe>, you need to switch to it first

WebElement iframe = driver.findElement(By.cssSelector("[src*='recruit'"])); //locate the iframe
driver.switchTo().frame(iframe);

And to switch back

driver.switchTo().defaultContent();
Sign up to request clarification or add additional context in comments.

Comments

1

use the below code to click on browse:

//first switch to iframe as the browse button is inside the iframe.
WebElement iframe = driver.findElement(By.cssSelector("[src*='recruit'"])); 
driver.switchTo().frame(iframe);

//scroll into the browse button
WebElement element = driver.findElement(By.id("theFile_link(Resume)"));
((JavascriptExecutor)   driver).executeScript("arguments[0].scrollIntoView(true);", element);

//now click on browse button
element.click();

hope it will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.