0

I have got an assignment to capture all apple stock history values in table. Link is this -https://finance.yahoo.com/quote/AAPL/history/

On inspecting table section, it is covered by this

 class="Pb(10px) Ovx(a) W(100%)" data-reactid="32"

As you can see, class name above contains lot of spaces therefore I need to come up with something like this .Pb(10px).Ovx(a).W(100%) tr

It works well when I use this string directly in chrome page [inspect elements->ctrl+F->copy above string) therefore used in my code like this (inspired from official documentation https://webdriver.io/docs/api/element/getText.html to get data from table) -

    const rows=$$('.Pb\(10px\).Ovx\(a\).W\(100\%\) tr');
    const C1 =rows[1].$$('td');
    const D1=C1[3].getText();

unfortunately, I get following error on running js code via webdriverio

[0-0] 2020-12-24T20:06:47.791Z INFO webdriver: COMMAND findElements("css selector", ".Pb(10px).Ovx(a).W(100%) tr")
[0-0] 2020-12-24T20:06:47.792Z INFO webdriver: [POST] 
http://localhost:9515/session/a6e01e59fd6304b8d56fb3360ac78ab3/elements
2020-12-24T20:06:47.792Z INFO webdriver: DATA { using: 'css selector', value: '.Pb(10px).Ovx(a).W(100%) tr' }
[0-0] 2020-12-24T20:06:47.824Z WARN webdriver: Request failed with status 400 due to invalid selector: An invalid or illegal selector was specified
(Session info: chrome=87.0.4280.88)

Tried many options, need advice from exerts :)

1 Answers1

1

The selector looks like this, works in wdio and chrome '[class*="Pb(10px)"][class*="Ovx(a)"][class*="W(100%)"]'. I'm not sure why would you need to rely on classes if you have data-test attribute almost everywhere, ex '[data-test="historical-prices"]' but it's up to you of course.

Mike G.
  • 3,512
  • 3
  • 14
  • 16
  • Thanks, it worked ! Can you share why .Pb\(10px\).Ovx\(a\).W\(100\%\) worked in chrome but not with wdio... – Ragner16 Dec 26 '20 at 19:33
  • Ah, I see, you just searched by text in element panel. You can't use it to validate css selector, use console – Mike G. Dec 27 '20 at 11:45