2016-10-09 20 views
0

아래의 웹 페이지에서 "찾아보기" 버튼을 클릭해야합니다.Selenium webdriver를 사용하여 "찾아보기"버튼을 클릭 할 수 없습니다.

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

나는 아래의 코드를 작성하지만, 찾아보기 버튼 요소를 찾기 위해 webdriver 실패했다. 도와주세요.

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(); 
    } 
} 

내가 사용하고 있습니다 :

파이어 폭스 버전 : 49.0.1

셀레늄 버전 : 버전 3.0.0-beta4

OS : Win10 64 비트

자바 : 1.8

+1

티켓을 예외 로그로 업데이트하십시오. 또한 왜 그 버튼을 클릭하고'/ input [@ id = "theFile_property (Resume) _1] 파일 경로를 보내는 대신'AutoIT' 스크립트를 실행하려고하는지 알려주십시오. – Andersson

+0

여기서 관련 HTML을 다음과 같이 공유 할 수 있습니까? 잘 –

답변

2

양식 (그리고 검색 버튼) 내부 <iframe>, 당신은 전환해야 그것은 첫째

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

그리고 다시

driver.switchTo().defaultContent(); 
1

를 전환 찾아보기를 클릭하려면 아래 코드를 사용하십시오 :

//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(); 

희망이 도움이 될 것입니다.

관련 문제