简体   繁体   English

奇怪的 XPath 行为

[英]Strange XPath behavior

Admittedly, I don't have much experience in selenium or advanced website building but this has had me stumped for a few days now诚然,我在 selenium 或高级网站建设方面没有太多经验,但这让我难倒了几天

After trying to get selenium to find this one element 20 different ways, I ended up just using chromes console to try and find it through there with the $x() command.在尝试让 selenium 以 20 种不同的方式找到这个元素之后,我最终只使用 chromes 控制台尝试通过 $x() 命令在那里找到它。 That's where I really got confused though, I have no idea why it's not finding it one second, then magically finding it the next这就是我真正感到困惑的地方,我不知道为什么它没有找到它,然后在下一秒神奇地找到它

here's what the console output looks like:这是控制台输出的样子:

奇怪的 xpath 行为

Strangely enough, even when I click on the element and retry the above xpath command, it still can't find it.奇怪的是,即使我点击元素并重试上面的 xpath 命令,它仍然找不到它。 The only way that i can get it to find the element is if I use chromes ctrl + shift + c command to click on the element and see it in element tab.我可以让它找到元素的唯一方法是,如果我使用 chromes ctrl + shift + c 命令单击元素并在元素选项卡中查看它。 I can't right click and inspect the element because it brings up it's own menu, it only works through that shortcut or clicking the button that activates that command.我无法右键单击并检查元素,因为它会显示它自己的菜单,它只能通过该快捷方式或单击激活该命令的按钮起作用。

I have a feeling this is why my Selenium script can't find the element and I'm not sure how to fix it or even why it's happening.我有一种感觉,这就是我的 Selenium 脚本找不到该元素的原因,我不确定如何修复它,甚至不确定它为什么会发生。 Any input that could help wrap my head around this would be appreciated greatly, thank you!任何可以帮助我解决这个问题的输入都将不胜感激,谢谢!

The element I wanted to click on was hidden under THREE iFrames which is why it couldn't find it.我想点击的元素隐藏在三个iFrame 下,这就是它找不到的原因。 After switching through them, the script functioned correctly - Thank you to Kajal Kundu for his simple question of asking for the HTML, I don't know why I didn't think of iframes possibly messing it up until I started copying the code for him :)切换它们后,脚本正常运行 - 感谢Kajal Kundu提出要求 HTML 的简单问题,我不知道为什么在我开始为他复制代码之前我没有想到 iframe 可能会搞砸它:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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