简体   繁体   中英

WebDriverIO 6 – $ works fine, $ doesn't work in iframe

I use WebDriverIO and try to access and click 2nd li tag inside iframe like this; HTML Image:
HTML 图像 . It's no iframe-id, li-id.

Now it works the following code

describe('research test', () => {
    it ('click object in iframe test', () => {
        browser.url('http://localhost/test/html/index.html');
        browser.pause(2000);
        browser.switchToFrame(0);
        $$('[class="inside-list-menu"]')[1].click(); 
        browser.pause(5000);
    });
});

But I want to change code of the following part

 $$ ('[class = "inside-list-menu"]') [1] .click ();

To

 $ ('[class = "inside-list-menu"]') [1] .click ();

but it failed.

I want to know

  1. Why $ doesn't work?

  2. Other way 2nd li tag is able to click start with $.

I'm using WebDriverIO version: 6. 14. 5 // Browser: Chrome // OS: Windows 10

There is a significant difference between $$ and $. To understand that better, please try to understand findElement and findElements from here .

In short, $$ returns an array of elements while $ returns first element that matches the selector.

Based on the return type of $$, you will select an element from array of elements using its index ( [1] in your case). The return type of $ is an element and when you use index to select it, it is fundamentally wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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