在尝试使用C#运行Selenium测试时,我遇到了一个问题,无法同时选中这两个“复选框”。
这是我为第一个复选框准备的,它确实有效,并选中了该框。driver.FindElement(By.XPath("//label@for='LegitimateCompanyAgreementCheckBox'")).Click();
但是,如果我简单地使用另一个复选框的标签"TermsOfServiceCheckBox",它不会选中该复选框,但它实际上会打开一个链接,因为这个复选框的措辞中有两个超链接。
例如,如果我尝试使用: driver.FindElement(By.XPath("//label@for='TermsOfServiceCheckBox'")).Click();,这将不会选中该框,它实际上会打开/terms-of-service的链接。
下面是我需要检查的两个复选框的代码。
<div class="asp-checkbox">
<span class="checkbox gaClick" data-category="companySignup" data-action="legitimateCompanyChecked" data-noninteraction="true">
<input id="LegitimateCompanyAgreementCheckBox" type="checkbox" name="ctl00$MainContent$LegitimateCompanyAgreementCheckBox">
<label for="LegitimateCompanyAgreementCheckBox">I am a legitimate estate sale company or auction company and have the documents necessary to conduct business in my state (if any).</label>
</span>
<label for="LegitimateCompanyAgreementCheckBox"></label>
<span id="LegitimateCompanyAgreementCheckBox_requredCheckBoxValidor" controltovalidate="LegitimateCompanyAgreementCheckBox" style="color:Red;visibility:hidden;">*
</span>
</div>
<span class="checkbox gaClick" data-category="companySignup" data-action="agreeToTermsChecked" data-noninteraction="true">
<input id="TermsOfServiceCheckBox" type="checkbox" name="ctl00$MainContent$TermsOfServiceCheckBox">
<label for="TermsOfServiceCheckBox">I agree to EstateSales.NET's <a href="/terms-of-service" class="gaClick" data-category="companySignup" data-action="termsOfServiceClicked" target="_blank">Terms of Service</a>
and <a href="/privacy-policy" class="gaClick" data-category="companySignup" data-action="privacyPolicyClicked" target="_blank">Privacy Policy</a>.
</label>
</span>发布于 2021-10-18 19:37:05
在这种情况下,我们不需要单击标签标签。实际的复选框是输入标记。尝试将Xpath设置为::driver.FindElement(By.Id("LegitimateCompanyAgreementCheckBox")).Click();或driver.FindElement(By.XPath("//input@id='LegitimateCompanyAgreementCheckBox'")).Click();
以下是Wait:
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 120));
WebElement element = wait.until(ExpectedConditions.ElementIsVisible(By.Id("LegitimateCompanyAgreementCheckBox")));
element.Click();https://stackoverflow.com/questions/69619835
复制相似问题