簡體   English   中英

如何使用 C# for Selenium 選中多個框

[英]How to check multiple boxes using C# for Selenium

在嘗試使用 C# 對 Selenium 運行測試時,我無法檢查這兩個“復選框”。

這是我對第一個復選框的看法,它確實有效並選中了該復選框。 driver.FindElement(By.XPath("//label[@for='LegitimateCompanyAgreementCheckBox']")).Click();

但是,如果我只是使用另一個復選框的標簽,即“TermsOfServiceCheckBox”,它不會選中該框,但它實際上會打開一個鏈接,因為該復選框在措辭中有 2 個超鏈接。

例如,如果我嘗試使用: 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>

在這種情況下我們不需要點擊標簽標簽。 實際的復選框是輸入標簽。 嘗試 Xpath 為 :: driver.FindElement(By.Id("LegitimateCompanyAgreementCheckBox")).Click(); 或 driver.FindElement(By.XPath("//input[@id='LegitimateCompanyAgreementCheckBox']")).Click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM