简体   繁体   English

无法在 Selenium 中找到元素?

[英]Unable to locate element in Selenium?

I am getting the following error in Pycharm:我在 Pycharm 中收到以下错误:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":".fbc-imageselect-checkbox-9"}

It is producing this error on this line:它在此行上产生此错误:

driver.find_element_by_css_selector('.fbc-imageselect-checkbox-9').click()

Where driver is the firefox, using selenium.其中driver是 firefox,使用 selenium。 I am attempting to click on the item that is linked to the CSS selector fbc-imageselect-checkbox-9 on the website: http://topg.org/Minecraft/in-414300我试图点击链接到网站上的 CSS 选择器fbc-imageselect-checkbox-9的项目: http : fbc-imageselect-checkbox-9

Please note, changing your user agent to mobile will produce the grid of images.请注意,将您的用户代理更改为移动设备将生成图像网格。

What am I doing wrong?我究竟做错了什么? Shouldn't this CSS selector work?这个 CSS 选择器不应该工作吗?

Should it work?它应该工作吗? Probably not.可能不是。 When I view the page there is no such element (UA "Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0"):当我查看页面时,没有这样的元素(UA "Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0"):

jQuery.find(".fbc-imageselect-checkbox-9")
Array [  ]

You probably need to rewrite your query a little more robustly.您可能需要更健壮地重写您的查询。

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

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