问题
In my page code, there is this script tag:
<script>
var oid = "182384";
document.getElementById('container').innerHTML = oGrid;
oGrid.setShowSid(false);
oGrid.calcSize();
setupAllTabs();
var toolbar = setupMenuButtons("btnbar");
initForm(toolbar);
</script>
How can I get the value of oid with watir or ruby?
回答1:
browser.script.html
will output the code within the <script>
tag. For example:
require 'watir'
browser = Watir::Browser.new
browser.goto("http://www.some_site_with_script.com")
browser.script.html
Then--as @rainkinz indicates--you can extract whatever values you want using regex:
b.script.html.match(/var\soid\s\=\s\"\d+\"/)
来源:https://stackoverflow.com/questions/15485345/how-get-the-value-of-a-script-tag