2013-03-11 5 views
1

로그인을 선택하면 Selenium Webdriver가 프레임을 찾는 방법을 알아낼 수 있습니까? 에서 SendKeys에서프레임이 발견되지 않은 Selenium Webdriver 문제가 발생했습니다.

https://www.guaranteedrate.com/agent/visitors 탭 기호

@Test

난 당신이 프레임에 촬영에 로그인을 클릭 한 후 생각
public void fail() throws InterruptedException { 


     driver.findElement(By.linkText("Sign In")).click(); 
      driver.switchTo().window("GB_window"); 
      driver.switchTo().frame(0);    driver.findElement(By.id("username")).sendKeys("[email protected]"); 
} 

답변

0

, 즉 등록 양식이다 사용자 이름입니다.

먼저 Windows (GB_Window)로 전환하십시오.

봅니다 창 호출 스위치를 제거하고 당신의 코드를 편집 한 후 사용자의 작업

구도를 시도 전환이

driver.findElement(By.linkText("Sign In")).click(); 
    driver.switchTo().frame(0); 
    driver.findElement(By.id("username")).sendKeys("[email protected]"); 

}

+0

전자 메일 주소에 커서가있는 프레임에 아무런 행운이 남지 않습니다. send 키가 아닙니다 .. 지금까지 많은 솔루션을 시도했습니다 ... – Selenio

+0

org.openqa.selenium.remote.UnreachableBrowserException : 오류 원격 브라우저와 통신. 그것은 사망했을 수도 있습니다. 빌드 정보 : 버전 : '2.30.0', 수정 버전 : 'dc1ef9c', 시간 : '2013-02-19 00:15:57' 시스템 정보 : os.name : 'Windows 7', os.arch : ' x86 ', os.version :'6.1 ', java.version :'1.6.0_17 ' 드라이버 정보 : driver.version : RemoteWebDriver – Selenio

0

가 아래 코드를 사용해보십시오 사용합니다. 그것은 나를 위해 일했습니다. 사용자 이름 요소를 찾기 전에 두 개의 프레임이 있습니다. 첫 번째 프레임은 GB_frame이고 두 번째 프레임은 HTML 소스에 지정된 이름이 없습니다. 그래서 두 번째 인덱스 (frame(0))를 사용했습니다.

@Test 

public void fail() throws InterruptedException {  

     driver.findElement(By.linkText("Sign In")).click(); 
     //switch to frames inside the webpage 
     driver.switchTo().frame("GB_frame"); //1st frame 
      driver.switchTo().frame(0); //2nd frame    
       driver.findElement(By.id("username")).sendKeys("[email protected]"); 
} 
+0

너무 빨리 움직이기 때문에 작업 한 결과 thread.sleeps를 넣어야했습니다. – Selenio

+0

@Gabriel Alexander 내 대답을 Upvote하거나 그것은 당신을 도왔거나 당신에게 정확한 해결책을 주면 좋은 대답으로 받아들입니다. – Hemanth

0

작동하는지 알려주시겠습니까? 나는 당신이 겪고있는 것이 파이어 폭스 만의 이상한 것이라는 의심을 품고, JavaScriptExecutor가 그 주위를 돌아 다닐 것으로 생각한다.

public void setEmailAddrOnFieldInSubFrame() { 
    driver.findElement(By.linkText("Sign In")).click(); 
    driver.switchTo().window("GB_window"); 
    driver.switchTo().frame(0); 
    WebElement element = driver.findElement(By.id("username")); 
    JavascriptExecutor executor = (JavascriptExecutor)driver; 
    executor.executeScript("arguments[0].value='[email protected]';", element); 

    //cleanup frame position by switching back to previous window 
    driver.switchTo().defaultContent(); // always do this cleanup just in case 
} 
0

응용 프로그램이 파이어 폭스에서 작동하는 경우 그럼 간단히 마우스 오른쪽 버튼으로 클릭하십시오. 컨텍스트 메뉴에서이 프레임 옵션을 보면 요소가 프레임 아래에 있는지 여부를 먼저 알 수 있습니다. 일단 이것을 확인하면 요소를 검사하십시오. 방화범 뚜껑에서 천천히 스크롤하면 요소가있는 iframe 태그를 찾을 수 있습니다. 이런 식으로 당신은 그 이름을 알게 될 것입니다. 모든 iframe 및 해당 이름의 수를 알고 싶다면 driver.findElements (By.tag ("iframe"))를 사용하십시오. 이렇게하면 태그가있는 webelements 목록이 반환되고 하나씩 차례로 반복하여 getAttribute ("name")을 사용할 수 있습니다. iframe이 실제로 다른 이름을 가진 다른 이름을 가진 경우에만 빈을 반환합니다.

관련 문제