问题
I am new to robot framework,
and want simulate control the jQuery component via executing jQuery
However, the Selenium2Library almost drives me crazy.
try to get value of the DOM component but the log shows NONE.
refer to http://d.pr/i/KXhw
The following is my test code.
Thanks in advance.
click configuration
[Tags] xpath
Open Browser http://${host} ie
Log "123"
${slide val}= Execute JavaScript window.jQuery("#gain_slider_handle").val();
${title}= Execute JavaScript window.$("head title")[0];
${t2}= Execute JavaScript window.eval('window.document.title')
Log ${slide val}
Log ${title}
And I try to use Python to do the same thing via selenium webdriver,
it also get the "None" value .
def setUp(self):
self.driver = webdriver.Ie(r"C:\\bin\\IEDriverServer.exe")
self.driver.implicitly_wait(10)
self.base_url = "http://172.19.1.28/setup/media/sensor.html"
self.verificationErrors = []
self.accept_next_alert = True
def test_py_robot(self):
driver = self.driver
driver.get(self.base_url )
print "title:" + str( driver.execute_script("document.title"))
print "wdr val:" + str( driver.execute_script("$('#wdr_strength').val()") )
回答1:
When you use jquery selector,you need to make sure web is loaded jquery package. if without,you can Execute JavaScript
var headID = document.getElementsByTagName(\"head\")[0];var newScript = document.createElement('script');newScript.type='text/javascript';newScript.src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';headID.appendChild(newScript);
来源:https://stackoverflow.com/questions/18608211/how-to-execute-jquery-using-selenium2library-under-robot-framework