简体   繁体   English

如何使用硒webdriver查找是否启用了元素?

[英]How to find an element is enabled or not using selenium webdriver?

I have used following code and currently my button is disabled.So code should return values as "false". 我使用了以下代码,当前我的按钮已禁用。因此代码应返回“ false”值。 But it is displaying value as "true".How to handle this one? 但是它显示的是“ true”值。如何处理呢? I have used element attribute is "ID". 我使用过的元素属性是“ ID”。 在此处输入图片说明

boolean val1 = fb.Element(ObjSWchat.chatunavailableicon).isEnabled();
                    System.out.println(val1);
                    if (val1=true) {
                        fb.ValidateTest(true, "Element is enabled");
                    } else {
                        fb.ValidateTest(true, "Element is disabled");
                        Assert.assertFalse(true);
                    }

HTML code: HTML代码:

<div id="enableChat" style="display: clock;">
                    <div id="EnableChat" class="xxxx_softwaredata iconchat">
                        <div id="myChatLinkContainer" class="rn_ConditionalChatLink">
                            <div id="myChatLink" class="">
                                <div id="myChatLinkInfo" class="">

                                <!-- -->
                                <span>Unavailable</span></div>
                            </div>
                        </div>

First of all here is the error: 首先这里是错误:

if (val1=true) {

should be 应该

if (val1==true) {

Try to use this wait: 尝试使用此等待:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

or 要么

wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));

Hope this would help, 希望这会有所帮助,

You have used the assignment operator(Single = is mentioned) and hence it is returning as true. 您已经使用了赋值运算符(提到了Single =),因此它返回的是true。 Please change your if condition as below(specify == ) 请更改您的if条件,如下所示(指定==)

            if (val1==true) {
                    fb.ValidateTest(true, "Element is enabled");
                } else {
                    fb.ValidateTest(true, "Element is disabled");
                    Assert.assertFalse(true);
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM