【发布时间】:2020-06-10 19:12:28
【问题描述】:
我尽一切努力让我的代码点击按钮,但它不能。我尝试使用 xpath、id、class。他们都没有工作。有没有人有这个想法?
HTML:
<div data-focus-lock-disabled="false" class="inner-1ilYF7">
<form class="modal-yWgWj- container-14fypd sizeSmall-1jtLQy fullscreenOnMobile-1aglG_">
<div class="scrollerWrap-2lJEkd content-1EtbQh scrollerThemed-2oenus themeGhostHairline-DBD-2d">
<div class="scroller-2FKFPG systemPad-3UxEGl inner-ZyuQk0 content-dfabe7">
<h2 class="h2-2gWE-o title-3sZWYQ defaultColor-1_ajX0 title-18-Ds0 marginBottom20-32qID7 marginTop8-1DLZ1n">WOAH THERE. WAY TOO SPICY</h2>
<div class="body-Mj9Oxz medium-zmzTW- primary-jw0I4K">You're sending messages too quickly!</div>
</div>
</div>
<div class="flex-1xMQg5 flex-1O1GKY horizontalReverse-2eTKWD horizontalReverse-3tRjY7 flex-1O1GKY directionRowReverse-m8IjIq justifyBetween-2tTqYu alignStretch-DpGPf3 wrap-ZIn9Iy footer-3rDWdC" style="flex: 0 0 auto;">
<button type="submit" class="primaryButton-2BsGPp button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeXlarge-2yFAlZ grow-q77ONN">
<div class="contents-18-Yxp">Enter the chill zone</div>
</button>
</div>
</form>
</div>
我查找按钮的代码如下所示:
try
{
var element = driver.FindElement(By.XPath("//*[text()='Enter the chill zone']"));
if (element.Displayed)
{
driver.FindElement(By.XPath("/html/body/div/div[2]/div[2]/div[2]/div[3]/form/div[2]/button")).Click();
Console.WriteLine("Button clicked!");
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
【问题讨论】:
-
能否分享一下按钮的html。
-
检查元素是否存在于 iframe 中?
-
您尝试单击的按钮是您提供的 HTML 中的父 BUTTON 吗?包含带有“进入寒冷区域”文本的 DIV 的那个?
-
现在检查html
-
@bial654321 iframe 可能比一个 div 标签更全球化。尝试在这个特定页面的整个 DOM 结构中搜索
标签: c# selenium selenium-webdriver discord