Last week, I started working on integrating a test suite previously built using Nightwatch, and making it work with webdriverIO. While I love all of webdriverIO's features like synchronous code when using their test runner and a REPL, there were a few things that I'd like to share which were a little hard to find in the docs or on a quick search.
Each day this week, I'll be posting one thing I've learned while getting started with webdriverIO. Here's the tip for today
Using $$.selector vs browser.elements(selector)
One of the first use cases I tackled in my test was finding all elements with a particular CSS class and then doing something to them. The docs seem to indicate that browser.$$(selector)
is a shorthand for browser.elements(selector)
and they seem to be synonymous except for a small difference:
$$(selector)
will return items that you can take an action like .click()
on
.elements(selector)
returns a WebElement JSON object (see more info about it on the github issue) - but its basically a JSON object that contains an ID (looks like a decimal number).
If you try to click on the first element in a group using something like browser.elements(selector)[0].click()
, you might get an error like Can't call click on undefined
because it does not return an array, but an object containing a key called value which has Ids for those elements.
Here's an example of the value of $$(selector)
> browser.$$(".link-gray-dark")
[ { ELEMENT: '0.15821111822631395-1',
'element-6066-11e4-a52e-4f735466cecf': '0.15821111822631395-1',
value: { ELEMENT: '0.15821111822631395-1' },
selector: '.link-gray-dark',
index: 0 },
{ ELEMENT: '0.15821111822631395-2',
'element-6066-11e4-a52e-4f735466cecf': '0.15821111822631395-2',
value: { ELEMENT: '0.15821111822631395-2' },
selector: '.link-gray-dark',
index: 1 },
....
and now compare that to browser.elements(selector)
> browser.elements(".link-gray-dark")
{ sessionId: '651d1e513eb87326a67969d65bbd597c',
value:
[ { ELEMENT: '0.15821111822631395-1',
'element-6066-11e4-a52e-4f735466cecf': '0.15821111822631395-1',
selector: '.link-gray-dark',
value: [Object],
index: 0 },
{ ELEMENT: '0.15821111822631395-2',
'element-6066-11e4-a52e-4f735466cecf': '0.15821111822631395-2',
selector: '.link-gray-dark',
value: [Object],
index: 1 },
For the most part, I can do everything I want to do with $$(selector)
since I'll usually try to find a group of elements and either click on them or input text on some of them.
One reason you might want to use browser.elements(selector)
instead would be if you needed to use one of the webdriver Protocol methods like elementIdClick(id)
or elementIdName(id)
, and elementIdScreenshot(id)
(which will take a screenshot of ONLY the element you want and not the whole page, neat!). Webdriver gives you a nice API so that you generally don't need to use these methods, but there are some nice features there if you do need to use them.
Recap
Prefer to use $$(selector)
since it should be enough for the majority of your use cases.
If you need access to some of the elementId*
methods like elementIdClick(id)
that show up under the Protocol section in the docs, then use browser.elements(selector)
.
214 Comments. Leave new
very satisfying in terms of information thank you very much. camarero
I totally agree with you. Actually warm ups can break up the students’ ice before starting th In Task activities. the engagement is the key role. the first step for a good teacher is engagement and as you said preparing students to step in lesson. thank you for sharing your experience.Thanks for this article and your advice!I will also try it in France)
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?
I have read your article carefully and I agree with you very much. This has provided a great help for my thesis writing, and I will seriously improve it. However, I don’t know much about a certain place. Can you help me?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your article helped me a lot, is there any more related content? Thanks!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/ka-GE/register?ref=V2H9AFPY
At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.
I may need your help. I’ve been doing research on gate io recently, and I’ve tried a lot of different things. Later, I read your article, and I think your way of writing has given me some innovative ideas, thank you very much.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.com/tr/register-person?ref=YY80CKRN
ينعكس التزام المصنع بالابتكار في جهود البحث والتطوير المستمرة لتحسين تصميم ووظائف تركيبات HDPE و uPVC الخاصة بهم. إيليت بايب Elite Pipe
The factory’s dedication to quality is evident in the superior performance of their HDPE pipes, which are known for their exceptional strength and durability. Elitepipe Plastic Factory
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/id/register?ref=GJY4VW8W
The factory’s uPVC fittings are designed with meticulous attention to detail, ensuring secure and tight connections that minimize the risk of leaks or failures. Elitepipe Plastic Factory
يمكن للعملاء الاعتماد على الخبرة الفنية لمصنع إيليت بايب Elite Pipeودعم العملاء المخصص لمساعدتهم في اختيار التركيبات الأنسب لاحتياجاتهم الخاصة.
Elitepipe Plastic Factory’s HDPE pipes offer excellent resistance to chemicals, abrasion, and environmental stress, making them ideal for a wide range of applications. Elitepipe Plastic Factory
توفر أنابيب HDPE من مصنع إيليت بايب Elite Pipe مقاومة ممتازة للمواد الكيميائية والتآكل والضغط البيئي ، مما يجعلها مثالية لمجموعة واسعة من التطبيقات.
Thank you very much for sharing, I learned a lot from your article. Very cool. Thanks. nimabi
Thank you for content. Area rugs and online home decor store. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Thank you for great information. Hello Administ .
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/sv/register?ref=JHQQKNKN
Thank you great post. Hello Administ .Casibom Website Giriş : Casibom
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader. Website : https://www.saricahali.com.tr/
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. Onwin , Onwin Giriş onwin
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader. Onwin , Onwin Giriş onwin
Thank you for great article. Hello Administ . Website : cami halısı
Everything is very open and very clear explanation of issues. was truly information.Onwin Giriş Website: onwin
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Everything is very open and very clear explanation of issues. was truly information.
Thank you for great content. Hello Administ.
I really love to read such an excellent article. Helpful article. Hello Administ .
Great post thank you. Hello Administ .
Thank you great posting about essential oil. Hello Administ . Website : cami halısı
Nice article inspiring thanks. Hello Administ .
Thank you great post. Hello Administ .
Thank you for great information. Hello Administ .
Thank you for great information. Hello Administ . Website Giriş için Tıklayın: tipobet
Thank you for content. Area rugs and online home decor store. Hello Administ . Website Giriş için Tıklayın: tipobet
Thank you great post. Hello Administ .Website Giriş için Tıklayın: tipobet
Thank you great posting about essential oil. Hello Administ . Website Giriş için Tıklayın: tipobet
Nice article inspiring thanks. Hello Administ . Website Giriş için Tıklayın: tipobet
Thank you for great information. Hello Administ . Website Giriş için Tıklayın: tipobet
Thank you great posting about essential oil. Hello Administ . Website Giriş için Tıklayın: tipobet
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.Website Giriş için Tıklayın: tipobet
Thank you for great content. Hello Administ. Website Giriş için Tıklayın: tipobet
Thank you for great information. Hello Administ . Website Giriş için Tıklayın: tipobet
Thank you for content. Area rugs and online home decor store. Hello Administ . Website Giriş için Tıklayın: tipobet
Nice article inspiring thanks. Hello Administ . Website Giriş için Tıklayın: tipobet
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://www.binance.com/pt-BR/register?ref=P9L9FQKY
Sumatra Slim Belly Tonic takes pride in its manufacturing process, ensuring that every batch is produced in FDA-approved and GMP-certified facilities. This means that each and every bottle of Sumatra Slim Belly Tonic meets the highest standards of quality and safety. You can trust that you are getting a product that has undergone strict quality control measures and is backed by scientific research.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Sugar Defender orchestrates a reduction in blood sugar levels through multifaceted pathways. Its initial impact revolves around enhancing insulin sensitivity, optimizing the body’s efficient use of insulin, ultimately leading to a decrease in blood sugar levels. This proactive strategy works to prevent the storage of glucose as fat, mitigating the risk of developing type 2 diabetes.
Thank you for content. Area rugs and online home decor store. Hello Administ .
Thank you for content. Area rugs and online home decor store. Hello Administ .
Great post thank you. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Everything is very open and very clear explanation of issues. was truly information.
Great post thank you. Hello Administ . sollet sollet
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great post. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you for content. Area rugs and online home decor store. Hello Administ .
Thank you great posting about essential oil. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Everything is very open and very clear explanation of issues. was truly information.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
I really love to read such an excellent article. Helpful article. Hello Administ .
Thank you for great information. Hello Administ .
Thank you great post. Hello Administ .
Nice article inspiring thanks. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Thank you great posting about essential oil. Hello Administ .
Great post thank you. Hello Administ .
Thank you for great content. Hello Administ.
Thank you great post. Hello Administ .
Thank you for great article. Hello Administ .
Thank you great post. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Nice article inspiring thanks. Hello Administ .
I really love to read such an excellent article. Helpful article. Hello Administ .
Everything is very open and very clear explanation of issues. was truly information.
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Thank you for great article. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great posting about essential oil. Hello Administ .
Great post thank you. Hello Administ .
Thank you for great content. Hello Administ.
Everything is very open and very clear explanation of issues. was truly information.
Good info. Lucky me I reach on your website by accident, I bookmarked it.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Thank you great post. Hello Administ .
Great post thank you. Hello Administ .
Thank you for great content. Hello Administ.
I appreciate how this blog promotes self-growth and personal development It’s important to continuously strive to become the best version of ourselves
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.com/id/register?ref=53551167
Thank you for content. Area rugs and online home decor store. Hello Administ . asyabahis asyabahis
Thank you for great article. Hello Administ . betforward extension betforward1.org
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Thank you for great article. Hello Administ .
Your writing has a way of making complicated topics easier to understand It’s evident how much research and effort goes into each post
Thank you for content. Area rugs and online home decor store. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
I really love to read such an excellent article. Helpful article. Hello Administ .
Nice article inspiring thanks. Hello Administ .
Great post thank you. Hello Administ .
Thank you for content. Area rugs and online home decor store. Hello Administ .
Nice article inspiring thanks. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great post. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Everything is very open and very clear explanation of issues. was truly information.
Thank you for great information. Hello Administ . venusbet deneme bonusu veren siteler
Thank you for content. Area rugs and online home decor store. Hello Administ .
Thank you for great article. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Great post thank you. Hello Administ .
Thank you for content. Area rugs and online home decor store. Hello Administ .
I really love to read such an excellent article. Helpful article. Hello Administ .
Thank you for great article. Hello Administ .
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
I really love to read such an excellent article. Helpful article. Hello Administ .
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Thank you great posting about essential oil. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Everything is very open and very clear explanation of issues. was truly information.
Thank you for content. Area rugs and online home decor store. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you for great information. Hello Administ .
Thank you for great article. Hello Administ .
Thank you great post. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great posting about essential oil. Hello Administ .
Thank you for great content. Hello Administ.
Thank you great post. Hello Administ .
I really love to read such an excellent article. Helpful article. Hello Administ .
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Thank you great post. Hello Administ .
I really love to read such an excellent article. Helpful article. Hello Administ .
Nice article inspiring thanks. Hello Administ .
I really love to read such an excellent article. Helpful article. Hello Administ .
Everything is very open and very clear explanation of issues. was truly information.
Thank you for great article. Hello Administ .
Thank you for great information. Hello Administ .
Thank you for great content. Hello Administ.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great post. Hello Administ .
Thank you for great content. Hello Administ.
Thank you for great information. Hello Administ .
Thank you great posting about essential oil. Hello Administ . matbet matbet
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Thank you for great information. Hello Administ .
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you for great content. Hello Administ.
Thank you for content. Area rugs and online home decor store. Hello Administ .
Thank you for great article. Hello Administ .
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Nice article inspiring thanks. Hello Administ .
Thank you great posting about essential oil. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great post. Hello Administ .
Great post thank you. Hello Administ .
Thank you for great information. Hello Administ .
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Thank you for great content. Hello Administ.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.info/pl/join?ref=GJY4VW8W
Supertotobet
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Everything is very open and very clear explanation of issues. was truly information.
Great post thank you. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Everything is very open and very clear explanation of issues. was truly information.
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you for great information. Hello Administ .
Thank you for content. Area rugs and online home decor store. Hello Administ .
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Thank you great post. Hello Administ .
Thank you great posting about essential oil. Hello Administ .
Great post thank you. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
I really love to read such an excellent article. Helpful article. Hello Administ .
Everything is very open and very clear explanation of issues. was truly information.
Thank you for great information. Hello Administ .
Thank you great posting about essential oil. Hello Administ .
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Nice article inspiring thanks. Hello Administ .
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Thank you for great content. Hello Administ.
Everything is very open and very clear explanation of issues. was truly information.
Thank you great posting about essential oil. Hello Administ .
Thank you great post. Hello Administ .
Thank you great post. Hello Administ .
Thank you for great article. Hello Administ .
Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.
After all, what a great site and informative posts, I will upload inbound link – bookmark this web site? Regards, Reader.
Bahsegel
Good info. Lucky me I reach on your website by accident, I bookmarked it.
Thank you for great content. Hello Administ. Website Giriş için Tıklayın: jojobet
Thank you for great article. Hello Administ .
Thank you for content. Area rugs and online home decor store. Hello Administ .
Thank you great post. Hello Administ .Website Giriş için Tıklayın: ganobet