2017-10-27 46 views
0

iframe을로드하는 페이지가 있지만 NoSuchElementError 오류 메시지가 표시됩니다. 내 코드 :셀레늄 webdriver (자바 스크립트)로 iframe 내부 버튼을 클릭 할 수 없습니다.

driver.wait(until.ableToSwitchToFrame(0)).then((d) => { 
    //*** SLEEP HERE 
    const button = By.css(".button"); 
    driver.wait(until.elementLocated(dropdownElem)).then((btn) => { 
    btn.click(); 
    }); 
}); 

우선 올바른 iframe을로 전환 후 나는 요소가 iframe을 내부에로드 될 때까지 기다립니다하려고합니다.

NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":".button" 
} 

하는 것이 왜 가능하게하지 않도록 driver.wait 라인이 요소에 대해 대기 않습니다 나는 그것이 작동 라인 //*** SLEEP HEREdriver.sleep(1000);을 삽입하는 경우는, 그렇지 않으면 실패?

+0

시도한 ['waitUntil'] (http://webdriver.io/api/utility/waitUntil.html)? – user1207289

+0

셀레늄이 관리하는 셀레늄 - webdriver nodejs 바인딩을 사용하고 있습니다. 당신이 링크 한 것은 다른 라이브러리 인 webdriverIO입니다. – marchello

+0

@marchello, 왜 'webdriverio'와 관련된 질문에 태그를 붙였습니까? – iamdanchiv

답변

0

로컬에서 테스트 해봤는데 Iframe의 버튼에 문제가없는 것으로 보입니다. 여기에 코드

var webdriver = require('selenium-webdriver'); 
var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build(); 
driver.get('file:///Users/../sampleFiles/sample-iframe.html'); 
driver.wait(webdriver.until.ableToSwitchToFrame(0)).then((d) => { 
    //*** SLEEP HERE 
    const button = webdriver.By.css(".Button"); 
    driver.wait(webdriver.until.elementLocated(button)).then((btn) => { 
    btn.click(); 
    btn.getTagName().then((tag) => { 
     console.log(tag); 
    }); 
    }); 


}); 

내가 콘솔

이이 테스트됩니다 iframe이 HTML에 button를 얻을, 당신의 driver.wait(until.elementLocated(dropdownElem)) 라인을 확인

<html lang="en"><head> 
    <meta charset="UTF-8"> 
    <title>Example of HTML Iframe</title> 
</head> 
<body> 
    <iframe src="file:///Users/../sampleFiles/sample.html" width="300" height="200"> 
     <html><head> 
<title>Page Title</title> 
</head> 
<body> 

<h1>This is a Heading</h1> 
<p>This is a paragraph.</p> 
<button id="ButtonID" class="Button">Click Me!</button> 


</body></html> 
    </iframe> 

    </body></html> 

되는 것 같다 것은 오타 프로그래머,

로 변경

driver.wait(until.elementLocated(button)) 그리고 다시 시도하십시오.