gpt4 book ai didi

c# - 如何使用 Selenium 和 C# 单击此特定元素

转载 作者:行者123 更新时间:2023-12-02 02:53:20 25 4
gpt4 key购买 nike

我已经尝试了很多方法,但似乎都不起作用,它不是一个明确的 id="ezidgrab" 该元素可以在此网址上找到:https://www.ahem.email/mailbox/QI2R89LNDT但我如何用 Selenium 点击那里的电子邮件?

我尝试过的:

1.

driver.FindElement(By.XPath("//p[contains(text(), 'Thank you for registering your email')]")).Click();

2.

driver.FindElement(By.TagName("mat-list-item")).Click();

3.

driver.FindElement(By.ClassName("mat-list-item-content")).Click();

和链接的 html:

<app-email-info _ngcontent-ahem-c5="" _nghost-ahem-c9="">
<mat-list-item _ngcontent-ahem-c9=""
class="ahem-hand-pointer mat-list-item ahem-email-unread mat-3-line">
<div class="mat-list-item-content">
<div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div>
<div class="mat-list-text">
<h2 _ngcontent-ahem-c9="" class="mat-line" mat-line="">Jagex</h2>
<p _ngcontent-ahem-c9=""
class="mat-line"
mat-line="">Thank you for registering your email</p>
<p _ngcontent-ahem-c9="" class="mat-line" mat-line="">9 minutes ago</p>
</div>
<fa-icon _ngcontent-ahem-c9="" class="ng-fa-icon">
<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="envelope" class="svg-inline--fa fa-envelope fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M464 64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V112c0-26.51-21.49-48-48-48zm0 48v40.805c-22.422 18.259-58.168 46.651-134.587 106.49-16.841 13.247-50.201 45.072-73.413 44.701-23.208.375-56.579-31.459-73.413-44.701C106.18 199.465 70.425 171.067 48 152.805V112h416zM48 400V214.398c22.914 18.251 55.409 43.862 104.938 82.646 21.857 17.205 60.134 55.186 103.062 54.955 42.717.231 80.509-37.199 103.053-54.947 49.528-38.783 82.032-64.401 104.947-82.653V400H48z"></path>
</svg>
</fa-icon>
</div>
</mat-list-item>
</app-email-info>

错误:

An unhandled exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll no such element: Unable to locate element: {"method":"xpath","selector":"//p[contains(text(), 'Thank you for registering your email')]"}

最佳答案

所需的元素是一个 Angular 元素,因此要在该元素上进行 Click(),您必须为 ElementToBeClickable() 引发 WebDriverWait 并且您可以使用以下任一Locator Strategies:

  • CSS选择器:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div.mat-list-text>h2"))).Click();
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='mat-list-text']/h2"))).Click();

关于c# - 如何使用 Selenium 和 C# 单击此特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59787187/

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