2017-01-19 3 views
0

그것은 양식을 가지고 this website.셀레늄은

의 요소를 확인하고이 텍스트 입력 1과 함께 버튼을 제출하시기 바랍니다. 사용자가 입력 할 때 실제로 사용되는 입력 2 개 중 어느 것이 있는지 알지 못합니다.

하지만 요소를 얻기 위해 (firefoxDriver사용)이 시도 할 때 :

WebElement textfieldURL = driver.findElement(By.id("ping-url")); // even ping-box not working 

요소를 찾을 수없는 결과의.

그때 나는이 내 코드를 변경 :

driver.switchTo().frame(driver.findElement(By.className("ping-iframe"))); 
WebElement textfieldURL = driver.findElement(By.id("ping-url")); // even ping-box not working 

결과는 여전히 요소를 찾을 수 없습니다입니다. 실마리가 있습니까?

답변

1

당신이 직면하고있는 exception을 언급하지 않았습니다.

driver.switchTo().frame(driver.findElement(By.className("ping-iframe"))); 
//or you can use frame index as well 
driver.switchTo().frame(0); 

당신의 요소는 ID ping-box 함께 사용할 수 있습니다 - iframe에서 현재 당신의 input 태그 그래서 당신은 첫 번째 프레임으로 전환하고보다하는 작업을 수행 할 수 있어야합니다. 다음 코드를 사용해보십시오. -

System.setProperty("webdriver.gecko.driver","D:/Application/geckodriver.exe"); 
driver = new FirefoxDriver(); 
driver.manage().window().maximize(); 
driver.get("https://www.twingly.com/ping"); 
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
driver.switchTo().frame(driver.findElement(By.className("ping-iframe"))); 
driver.findElement(By.id("ping-box")).sendKeys("http://www.google.com"); 
driver.findElement(By.id("ping-button")).click(); 

같은 것이 맞습니다.

+0

시간 초과에 대한 감사, 그 대답을 보인다 : D 조 – gumuruh