No such element exception shown if element not present

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

No such element exception shown if element not present

sreedevivasudevan91
try{
boolean k= driver.findElement(By.xpath(" ")).isDisplayed();
if(!k==true)
{
System.out.println("true12"); 
 
}
}
else {
System.out.println("false12"); 
}
}catch (NoSuchElementException e) {
System.out.println(e);
         }
i want to check negative condition.
above boolean element is not displayed ,but i have to print true and false but it shows no such element exception
please help.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fff25429-f04f-478f-bc36-31db5de9cade%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: No such element exception shown if element not present

Shiva Prasad Adirala
If element is not found then .isDisplayed will throw and exception. I will verify the case as follow's

boolean result = false;
try {
    boolean result= driver.findElement(By.xpath(" ")).isDisplayed();
} catch (NoSuchElementException e) {
    System.out.println(e);
}

if (result) {
    System.println("true12");
} else {
    System.println("false12");
}

On Saturday, June 23, 2018 at 9:23:28 PM UTC+5:30, [hidden email] wrote:
try{
boolean k= driver.findElement(By.xpath(" ")).isDisplayed();
if(!k==true)
{
System.out.println("true12"); 
 
}
}
else {
System.out.println("false12"); 
}
}catch (NoSuchElementException e) {
System.out.println(e);
         }
i want to check negative condition.
above boolean element is not displayed ,but i have to print true and false but it shows no such element exception
please help.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ac7ef84e-cd34-432c-8d1b-6ae74ffe4fd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: No such element exception shown if element not present

sreedevivasudevan91
but cant assign result in 2 places. boolean result=false,
boolean result =xpath

On Saturday, June 23, 2018 at 9:30:23 PM UTC+5:30, Shiva Prasad Adirala wrote:
If element is not found then .isDisplayed will throw and exception. I will verify the case as follow's

boolean result = false;
try {
    boolean result= driver.findElement(By.xpath(" ")).isDisplayed();
} catch (NoSuchElementException e) {
    System.out.println(e);
}

if (result) {
    System.println("true12");
} else {
    System.println("false12");
}

On Saturday, June 23, 2018 at 9:23:28 PM UTC+5:30, [hidden email] wrote:
try{
boolean k= driver.findElement(By.xpath(" ")).isDisplayed();
if(!k==true)
{
System.out.println("true12"); 
 
}
}
else {
System.out.println("false12"); 
}
}catch (NoSuchElementException e) {
System.out.println(e);
         }
i want to check negative condition.
above boolean element is not displayed ,but i have to print true and false but it shows no such element exception
please help.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/070f4a65-32f5-4550-b89c-3dd8acff37c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: No such element exception shown if element not present

Shiva Prasad Adirala
My bad.

Remove boolean 2nd time.
result = drive.findElem();

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3cb856dd-69e3-4cd3-9a88-7edd4f2ec310%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.