2017-10-27 10 views
0

iframeを読み込むページがありますが、NoSuchElementErrorというエラーメッセージが表示されます。 マイコード:セレンのwebdriver(JavaScript)で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内でロードされるのを待つようにしてください。 私はそれ以外の場合は失敗し、それが動作ライン//*** SLEEP HEREdriver.sleep(1000);を挿入した場合:

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

driver.wait回線が使用可能になるための要素を待っていないのはなぜ?

+0

試した['waitUntil'](http://webdriver.io/api/utility/waitUntil.html)? – user1207289

+0

私はselenium-webdriver nodejsバインディングを使用しています。あなたがリンクしているものはwebdriverIOです。これは別のライブラリです。 – marchello

+0

@marchello、なぜあなたはwebdriverio関連の質問にタグを付けましたか? – iamdanchiv

答えて

0

私はこれをローカルでテストしましたが、これはIframe内のボタンでうまく機能しているようです。ここで私はこれが上でテストされてbutton

コンソール上とiframe HTMLが

<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(dropdownElem))ラインをチェックし、タイプミスtheresのようで、

に変更している取得するコード

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


}); 

です

driver.wait(until.elementLocated(button))してもう一度お試しください

関連する問題