vendredi 2 janvier 2015

Undefined javascript function in Selenium test with Capybara


I have a page with a Javascript function in HTML on the page:



<body>
...


<script type="text/javascript">

function myfunc(){
// do smth
}
</script>

</body>


I'm using Capybara with Selenium Webdriver in my RSpec tests.


After visiting this page I want to call this function:



it "my test" do
visit "http://ift.tt/1xePZkp"

page.execute_script "myfunc(); "

end


Almost all time this test is OK. But sometimes I get an error:



Selenium::WebDriver::Error::JavascriptError: myfunc is not defined


How to fix this problem? Is it because Selenium is calling the function before the whole HTML page (with Javascript on it) is loaded ?





Aucun commentaire:

Enregistrer un commentaire