-
Notifications
You must be signed in to change notification settings - Fork 53
nth-child
selector seems not working properly
#1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
And I encountered the same problem just now... Have you figured out the solution yet? |
@Livinglist No I didn't find any fix, so I ended up to avoid the The code is ugly and hard to read, but it works. |
Same issue, nth-child does not seem to be supported, which is a bummer |
Nth-child will be supported : dart-archive/html#101 |
It has been 2 years.. Is this gonna be implemented or not? I really need querySelector() to work... |
you can try universal_html |
yeah, that's the one I'm using now. I forgot to mention it here. |
Still doesn't work correctly.... |
中文: 奇妙的规律可以使用nth-child <!-- note -->
<div>...</div>
<div>目标</div> 中文: 注释算2个单位,目标div之前的div算2个单位,获取目标4+1,即:nth-child(5) |
I go through selector code implementation in html package and I found the nth-child selector for some reason is offset by one from js , so the solution is remove one from what ever you try to get for example if the selector in js look like this |
@Masood-1 Removing one not works with my code. Actually I didn't realize I'm matching a part of html code like this: <dd>
<em>
<font color="#666">foo1</font>
<font color="#0099FF">bar1</font>
</em>
<em>
<font color="#666">foo2</font>
<font color="#99CC00">bar2</font>
</em>
<em>
<font color="#666">foo3</font>
<font color="#FF3399">bar3</font>
</em>
</dd> Using something like: final bar1Text = element.querySelector('em:nth-child(1) > font:nth-child(2)').text;
final bar2Text = element.querySelector('em:nth-child(2) > font:nth-child(2)').text;
final bar3Text = element.querySelector('em:nth-child(3) > font:nth-child(2)').text;
Giving it an offset also not work. So I have to use a workaround like: final bar1Text = element.childAtOrNull(0)?.childAtOrNull(1)?.text;
final bar2Text = element.childAtOrNull(1)?.childAtOrNull(1)?.text;
final bar3Text = element.childAtOrNull(2)?.childAtOrNull(1)?.text; |
Uh oh!
There was an error while loading. Please reload this page.
I found
nth-child
selector is not working as expected.Having a simple html
And running tests as below
nth-child
yieldsnull
The text was updated successfully, but these errors were encountered: