How to check for an element if it exists or not?

182 views
Skip to first unread message

hunsnowboarder02

unread,
Dec 19, 2015, 7:57:57 AM12/19/15
to Selenium Users
Hi Everyone!

I am having another frustrating problem with selenium.

I am using VBA + Selenium and I am trying to check wether an elemnent exists or not.

I am doing it by finding the element and checking it's size. If it is 0 it means that it is not present.

I use the following code:
element_size = driver.FindElementByCss("div.toto > p:nth-child(6)").Size

I am probably using it wrong because I get an "object doesn't support this property" error. However if I use:

element_size = driver.FindElementByCss("div.toto > p:nth-child(6)").Text

Then I get the desired text.

So what is wrong with my size code? ( I also tried .size() but I get the same error)

Thanks for your help in advance and have a nice weekend!

hunsnowboarder02

unread,
Dec 20, 2015, 2:15:29 PM12/20/15
to Selenium Users
Could sombedy help with this issue, please?

PeterJeffreyGale

unread,
Dec 20, 2015, 6:06:46 PM12/20/15
to Selenium Users
Where does it say that a FindElementBy method has size property?

lkat...@tripodtech.net

unread,
Dec 21, 2015, 6:53:35 AM12/21/15
to Selenium Users
 FindElement method does not have size property. The size property is for FindElements method. You can try it.

Ripon Al Wasim

unread,
Dec 21, 2015, 7:21:10 AM12/21/15
to seleniu...@googlegroups.com
Simply, you can call isElementPresent( By by) method.

--
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 selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/2a3c1733-906f-4a56-afb7-348eaf593856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages