gpt4 book ai didi

javascript - 苹果脚本 : Javascript to click in safari with unknown id

转载 作者:行者123 更新时间:2023-11-30 19:35:34 24 4
gpt4 key购买 nike

如何点击下面列出的“详细信息”按钮?

<span data-segment-id="bererf44b-be45-4514-922a-0fff0585gb">
<input type="radio" id="dccd7242-38d2-4f54-4841-73c4b48a2f56-view-selector-bererf44b-be45-4514-922a-0fff0585gb" name="dccd7242-38d2-4f54-4841-73c4b48a2f56-view-selector" value="detailed">
<label for="dccd7242-38d2-4f54-4841-73c4b48a2f56-view-selector-bererf44b-be45-4514-922a-0fff0585gb">Detailed</label>
</span>

这个工作,但我必须手动输入加密的 id

tell application "Safari Technology Preview" to ¬
do JavaScript ¬
"document.querySelectorAll(\"[for=\\\"dccd7242-38d2-4f54-4841-73c4b48a2f56-view-selector-bererf44b-be45-4514-922a-0fff0585gb\\\"]\")[0].click();" in current tab of window 1

更新:

大部分 HTML 都是动态的,我不能太依赖它。

<div class="center">
<div class="segmented-control view-selector component" id="THIS_IS_DYNAMIC">
<input type="radio" id="THIS_IS_DYNAMIC" name="THIS_IS_DYNAMIC" value="basic">
<label for="THIS_IS_DYNAMIC">Basic</label>
</span><span data-segment-id="THIS_IS_DYNAMIC">
<input type="radio" id="THIS_IS_DYNAMIC" name="THIS_IS_DYNAMIC" value="detailed">
<label for="THIS_IS_DYNAMIC">Detailed</label>
</span></div>
</div>

最佳答案

据我了解,您希望触发对 <label 的点击元素。您的主要问题是您必须手动输入加密的 ID。

我建议您搜索 <label值为 'Detailed' 的元素.

[...document.querySelectorAll('label')].find(x=>x.innerText=='Detailed' || x.textContent == 'Detailed').click(); //triggers onclick

// or use

Array.from(document.querySelectorAll('label')).find(x=>x.innerText=='Detailed' || x.textContent == 'Detailed').click()


// hint. document.querySelectorAll doesn't return a normal array but a nodelist

编辑:已更改 <input元素到 <label元素。

关于javascript - 苹果脚本 : Javascript to click in safari with unknown id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55981349/

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