【发布时间】:2020-10-20 00:25:36
【问题描述】:
当按钮出现在网页上时,我想以编程方式点击它,有什么方法吗?
这里是按钮,没有ID,只有这个;
<div class="VotingButtons"><button class="VotingButton VotingButton--upvote btn-white" type="button">Like</button>
以下是有关按钮的更多信息:
<div class="VotingWrapper VotingWrapper--isBlocking"><p class="VotingWrapper__text"><strong>Do you like this image?</strong></p><div class="VotingButtons"><button class="VotingButton VotingButton--upvote btn-white" type="button">Like</button><button class="VotingButton VotingButton--downvote btn-white" type="button"><span class="VotingButton__text--hideOnMobile">Dislike</span></button></div></div>
我尝试使用此代码,但它不起作用:
private async void Btn_GoToDirectly_Click(object sender, EventArgs e)
{
var script = @"
document.getElementsByClassName('VotingButton VotingButton--upvote btn-white')[0].click();
browser.ExecuteScriptAsync(script);
";
browser.ExecuteScriptAsync("document.getElementByClassName('VotingButton VotingButton--upvote btn-white').click()");
【问题讨论】:
-
来自tagging help page:你应该在标题中使用标签的唯一情况是它们与标题的对话语气有机。用你的格式引用那个页面'已尝试使用:“避免在以下任何格式的标题中插入标签:” “[tag]: [question title]” and “[question标题] -- [标签] [标签] [标签]".
-
确保您的 JavaScript 在 DevTools 中工作。请参阅github.com/cefsharp/CefSharp/wiki/…,您应该从 JavaScript 中删除 ExecuteScriptAsync。
-
@amaitland 不幸的是,没有...
标签: javascript c# cefsharp chromium-embedded