当前位置: 首页 > 知识库问答 >
问题:

asp.netRadioButton显示false总是硒

洪弘毅
2023-03-14

我有一个UI,如下所示,我正在尝试将其自动化

我的html内容如下:

<div class="medium-5 columns tableheading-td">
  <ul id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers" class="assessment-main-layout tabled-list" onchange="ChangeTextColorForSelectedRadio(this);">
    <li>
      <input id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0" type="radio" name="ctl00$ctl00$ContentPlaceHolder1$QuetionListPlaceHolder$BigFiftyPersonalityQuestion1$BigFiftyPersonalityQuestionItem1221754$rdbListAnswers"
        value="0">
      <label for="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0"> </label>
    </li>
    <li>
      <input id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_1" type="radio" name="ctl00$ctl00$ContentPlaceHolder1$QuetionListPlaceHolder$BigFiftyPersonalityQuestion1$BigFiftyPersonalityQuestionItem1221754$rdbListAnswers"
        value="1">
      <label for="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_1"> </label>
    </li>
    <li>
      <input id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_2" type="radio" name="ctl00$ctl00$ContentPlaceHolder1$QuetionListPlaceHolder$BigFiftyPersonalityQuestion1$BigFiftyPersonalityQuestionItem1221754$rdbListAnswers"
        value="2" style="">
      <label for="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_2"> </label>
    </li>
    <li>
      <input id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_3" type="radio" name="ctl00$ctl00$ContentPlaceHolder1$QuetionListPlaceHolder$BigFiftyPersonalityQuestion1$BigFiftyPersonalityQuestionItem1221754$rdbListAnswers"
        value="3">
      <label for="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_3"> </label>
    </li>
    <li>
      <input id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_4" type="radio" name="ctl00$ctl00$ContentPlaceHolder1$QuetionListPlaceHolder$BigFiftyPersonalityQuestion1$BigFiftyPersonalityQuestionItem1221754$rdbListAnswers"
        value="4">
      <label for="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_4"> </label>
    </li>
  </ul>
</div>

我正在尝试按以下方式单击我的单选按钮:

IWebElement webElement= CommonProperties.driver.FindElement(By.Id("ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_2"));
webElement.ClickElement();

我已经尝试与xpath:

 IWebElement webElement= CommonProperties.driver.FindElement(By.XPath("//*[@id='ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0']"));

(单选按钮和标签有两个xpath。即使遇到相同的问题。

//*[@id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0"]

//*[@id="ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers"]/li[1]/label

OpenQA. Selenium.消息=元素不可见(会话信息:铬=72.0.3626.109)
(驱动程序信息:铬驱动=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),平台=Windows NT 10.0.10586x86_64)Source=WebDriver

StackTrace:在OpenQA. Selenium.远程。远程网络驱动。OpenQA. Selenium上的Unpack AndThrowOnError(响应错误响应)。远程。远程网络驱动。在OpenQA. Selenium上执行(String driverDirecdToExecute, Dicpedia2参数)。远程。远程网络元素。在OpenQA. Selenium上执行(String命令ToExecute,字典2参数)。远程。远程网络元素。单击()在SeleniumBL. SeleniumSetWay.D:\SourceControl\Test\Test\SeleniumHR\SeleniumHR\SeleniumBL\SeleniumSetM中的ClickElement(IWebElement元素)ethods.cs:SeleniumHR. Model的第53行。评估。Big50tyAssesment.AssesmentPlay()in D:\SourceControl\Test\Test\SeleniumHR\SeleniumHR\Models\Assesment\Big50tyAssesment.cs:在SeleniumHR. Model的第47行。评估基地。AssesmentStart()在D:\SourceControl\Test\Test\SeleniumHR\SeleniumHR\Models\Assesment\AssesmentBase.cs:行216在SeleniumHR. Model。评估。Big50tyAssesment.执行评估()在D:\SourceControl\Test\Test\SeleniumHR\SeleniumHR\SeleniumHRM\Models\Assesment\Big50tyAssesment.cs:第24行在SeleniumHR. Model。评估。评估工厂。AssesmentPlay(String AssesmentType)in D:\SourceControl\Test\Test\SeleniumHRM\SeleniumHR\SeleniumHR\Models\Assesment\AssesmentFactory.cs: line 48 at SeleniumHRM. Program.D:\SourceControl\Test\Test\SeleniumHR\SeleniumHR\SeleniumHR\Program.cs: line 49中的Main(String[]args)

共有3个答案

宋英杰
2023-03-14

我能够找出我的问题。根据样式类单选按钮是禁用的。因此它总是显示false。我能够点击单选按钮使用点击相关的标签文本。我是这样做的

 // get lable for selected radio button
IWebElement radioButtonSelectedLabel = CommonProperties.driver.FindElement(By.CssSelector("label[for='ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0']"));
// click on the label
radioButtonSelectedLabel.ClickElement();
柳轶
2023-03-14

您可以尝试使用visibilityOfElement在单击之前将其定位为等待元素

WebDriverWait wait = new WebDriverWait(driver, 10);
var clickableElement = wait.Until(ExpectedConditions.visibilityOfElementLocated(By.XPath("//*[@id='ContentPlaceHolder1_QuetionListPlaceHolder_BigFiftyPersonalityQuestion1_BigFiftyPersonalityQuestionItem1221754_rdbListAnswers_0']")));
蒯卓君
2023-03-14
exception details : element not visible (Session info: chrome=72.0.3626.109) (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.10586 x86_64)

这表明您正在使用较旧版本的chromedriver=2.37。544315与chrome版本72不兼容。您需要升级您的chrome驱动程序才能兼容。我相信这会解决你的问题。

请看以下链接。

 类似资料:
  • 问题内容: 我已经写了这段简单的代码: 在我的情况当属。谁能建议/建议出什么问题了? 问题答案: 错误检查和处理是程序员的朋友。检查初始化和执行cURL函数的返回值。并在失败的情况下包含更多信息: *在 手动状态: 成功返回cURL句柄,错误返回 FALSE 。 我观察到该函数在您使用其参数且无法解析域时会返回。如果未使用该参数,则该函数 可能 永远不会返回。但是,请务必始终进行检查,因为该手册并

  • 我想检查模型是否已更改isDirty方法,但总是返回false。 这是我的代码:

  • 为什么运行应用程序时返回false? 我使用它来控制日志,如下所示:

  • 问题内容: 我找到了JavaDoc的方法: 返回:如果此线程已被中断,则返回true;否则返回false。 否则为假。 我对这种方法的理解有误。此外,我可能会误解Thread中的“中断”概念。 欢迎任何解释!谢谢! 程式码片段: 在线程定义中: 调用: 问题答案: 引发异常后,线程不再处于中断状态。

  • 我试图解析这样的字符串; /^/^这是一个大/*这是一个粗体文本/-这是删除。我需要$/^和$之间的文本 在regexr和java regex tester上对regex进行了测试,并显示了它的工作状态。

  • 我正在尝试使用equals方法与对象进行比较,但它总是返回false