[英]How can I insert text into an input field on another page?
I have a list of URLs and some info on a Google Sheet and managed to open the URLs with a Google Apps Script.我在 Google 表格上有一个 URL 列表和一些信息,并设法使用 Google Apps 脚本打开了这些 URL。 On the page that opens, there are 2 input fields and a confirm button.
在打开的页面上,有 2 个输入字段和一个确认按钮。 I need the script to get info from the spreadsheet (which I saved as variables) and input them into these fields.
我需要脚本从电子表格(我保存为变量)中获取信息并将它们输入到这些字段中。 After that, I need the script to click on the submit button.
之后,我需要脚本来点击提交按钮。
I'm not entirely sure this would be the solution, but I figured I would need to get the input field element by id and then insert the variable in it.我不完全确定这是否是解决方案,但我认为我需要通过 id 获取输入字段元素,然后将变量插入其中。 But I wasn't able to do it because
getElementById()
doesn't work with Google Apps Script.但我无法做到这一点,因为
getElementById()
不适用于 Google Apps 脚本。
I did quite some digging and only found solutions that used the HTML file on a Google Apps Script.我做了一些挖掘工作,只找到了在 Google Apps 脚本上使用 HTML 文件的解决方案。 However, I don't know if it would help solve this issue and I honestly didn't understand much of it.
但是,我不知道它是否有助于解决这个问题,老实说,我不太了解它。 I guess it would only add unnecessary steps since I already managed to open the page on another tab.
我想这只会增加不必要的步骤,因为我已经设法在另一个选项卡上打开了该页面。
I have the ID of the first input field.我有第一个输入字段的 ID。 The second field is one "Tab hit" away from the first one and has a dynamic ID, so it won't work when I loop the script to do it with all the URLs.
第二个字段与第一个字段相距一个“Tab hit”,并且具有动态 ID,因此当我循环脚本以使用所有 URL 执行此操作时,它将不起作用。 The only property that seems unique to it is the aria-label (I don't know if it helps).
似乎唯一的属性是 aria-label (我不知道它是否有帮助)。 The submit button doesn't have an ID but it has a unique class and a type="submit" (I can see it on inspect but not when I open the source code on another page, don't know if there's a difference).
提交按钮没有 ID,但它有一个唯一的类和一个 type="submit"(我可以在检查时看到它,但当我在另一个页面上打开源代码时看不到,不知道是否有区别) .
I already managed to open the URLs on another tab and save the info on variables, now I'm stuck on the step that inserts them on the input fields and clicks the submit button.我已经设法在另一个选项卡上打开 URL 并保存变量信息,现在我被困在将它们插入输入字段并单击提交按钮的步骤上。
Here's my code so far:到目前为止,这是我的代码:
function fulfill() {
var rangeValues = searchRange.getValues();
var orderId = rangeValues[604][1];
var trackingNumber = rangeValues[604][3];
var shippingCompany = rangeValues[604][4];
var url = "https://someshopifystore.myshopify.com/admin/orders/" + orderId + "/fulfill_and_ship?fulfill_only=true&fulfillment_service_handle=manual&location_id=2085355564&requires_shipping=true";
var html = "<script>window.open('" + url + "');google.script.host.close();</script>";
var userInterface = HtmlService.createHtmlOutput(html);
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab');
}
OBS1: I need to solve it through Google Sheets and Google Apps Script because it's part of a wider solution. OBS1:我需要通过 Google 表格和 Google Apps 脚本来解决它,因为它是更广泛解决方案的一部分。
OBS2: The page that opens is a fulfillment page from Shopify. OBS2:打开的页面是 Shopify 的履行页面。
<script> </script>
part of a HTML file.<script> </script>
部分。getElementById()
).getElementById()
)。google.script.run
method .google.script.run
方法。payload
within the request options.payload
请求选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.