gpt4 book ai didi

javascript - ruby 变量在 driver.execute_script 之后返回 nil

转载 作者:行者123 更新时间:2023-11-28 01:34:22 24 4
gpt4 key购买 nike

我试图返回一串用逗号分隔的很长的网址。该代码在控制台中运行良好,但是当我执行脚本时,ruby 变量 urls_list 为零。

require 'rubygems'
require 'selenium-webdriver'
require 'json'


driver = Selenium::WebDriver.for :firefox
driver.manage.timeouts.implicit_wait = 20

driver.get "https://go.urbanairship.com/accounts/login/"
username = driver.find_element(:id, "id_username").send_keys "????"
password = driver.find_element(:id, "id_password").send_keys "????"
submit = driver.find_element(:class, "important").click

urls_list = driver.execute_script( "
var urls = [];
for (var i = 1; i < 37; i ++) {
(function (i){
$.getJSON('https://go.urbanairship.com/apps/-/list/'+ i + '/per_page=20').then(function(data) {
var json = data;
for (var j = 0; j < json.objects.length; j++) {
var url = json.objects[j].url
urls.push(url);
}
});
}(i));

}
urls.toString();

")

sleep 10
puts urls_list # urls_list is nil

最佳答案

您必须向驱动程序提供更多有关脚本返回内容的提示。

例如,将其更改为:

return urls.toString();

关于javascript - ruby 变量在 driver.execute_script 之后返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21712395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com