鱼C论坛

 找回密码
 立即注册
查看: 3325|回复: 17

selenium点击这个元素

[复制链接]
发表于 2023-5-20 13:29:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 歌者文明清理员 于 2023-5-20 13:32 编辑

如题,,,死活不能点到
  1. <button class="transition text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-200"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class=" iconify iconify--ri" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M12 3c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Zm0 14c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Z"></path></svg></button>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-5-20 13:31:38 | 显示全部楼层
  1. [quote][size=2][url=forum.php?mod=redirect&goto=findpost&pid=6239203&ptid=228526][color=#999999]isdkz 发表于 2023-5-20 13:29[/color][/url][/size]
  2. 您好,这个问题可能是由于以下原因导致的:

  3. 1. 元素未加载:如果元素未加载完成,尝试等待一段时间再尝试 ...[/quote]

  4. E:\Python\e\venv\Scripts\python.exe E:\python\e\main.py
  5. Traceback (most recent call last):
  6.   File "E:\python\e\main.py", line 10, in <module>
  7.     answer = ai.ask(question)
  8.   File "E:\python\e\gpt.py", line 39, in ask
  9.     ActionChains(self.driver).move_to_element(self.driver.find_element(
  10.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 831, in find_element
  11.     return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  12.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
  13.     self.error_handler.check_response(response)
  14.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
  15.     raise exception_class(message, screen, stacktrace)
  16. selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified
  17.   (Session info: chrome=113.0.5672.127)
  18. Stacktrace:
  19. Backtrace:
  20.         GetHandleVerifier [0x004F8893+48451]
  21.         (No symbol) [0x0048B8A1]
  22.         (No symbol) [0x00395058]
  23.         (No symbol) [0x003983F1]
  24.         (No symbol) [0x00399631]
  25.         (No symbol) [0x003996D0]
  26.         (No symbol) [0x003C00C0]
  27.         (No symbol) [0x003C069B]
  28.         (No symbol) [0x003EDD92]
  29.         (No symbol) [0x003DA304]
  30.         (No symbol) [0x003EC482]
  31.         (No symbol) [0x003DA0B6]
  32.         (No symbol) [0x003B7E08]
  33.         (No symbol) [0x003B8F2D]
  34.         GetHandleVerifier [0x00758E3A+2540266]
  35.         GetHandleVerifier [0x00798959+2801161]
  36.         GetHandleVerifier [0x0079295C+2776588]
  37.         GetHandleVerifier [0x00582280+612144]
  38.         (No symbol) [0x00494F6C]
  39.         (No symbol) [0x004911D8]
  40.         (No symbol) [0x004912BB]
  41.         (No symbol) [0x00484857]
  42.         BaseThreadInitThunk [0x75FB00C9+25]
  43.         RtlGetAppContainerNamedObjectPath [0x773B7B4E+286]
  44.         RtlGetAppContainerNamedObjectPath [0x773B7B1E+238]


  45. 进程已结束,退出代码1
复制代码
  1. <button class="transition text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-200"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class=" iconify iconify--ri" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M12 3c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Zm0 14c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Zm0-7c-1.1 0-2 .9-2 2s.9 2 2 2s2-.9 2-2s-.9-2-2-2Z"></path></svg></button>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 13:38:25 | 显示全部楼层
isdkz 发表于 2023-5-20 13:38
看起来应该是你的选择器的语法错了


那正确的选择器语法应该是?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 13:40:45 | 显示全部楼层
本帖最后由 歌者文明清理员 于 2023-5-20 13:50 编辑

isdkz 发表于 2023-5-20 13:39
ActionChains(self.driver).move_to_element(self.driver.find_element(  这一句后面是怎么写的?

  1. ActionChains(self.driver).move_to_element(self.driver.find_element(
  2.             By.CLASS_NAME, " iconify iconify--ri"
  3.         )).click().perform()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 13:51:34 | 显示全部楼层
本帖最后由 歌者文明清理员 于 2023-5-20 13:53 编辑

isdkz 发表于 2023-5-20 13:49
你传递给  find_element  方法的选择器是无效的。你正在试图用  By.CLASS_NAME  去查找一个元素,它的类 ...


没报错,可是没效果
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 13:53:47 | 显示全部楼层


你也用snipaste?

我是说
  1. By.XPATH, "//*[@class='iconify iconify--ri']"
复制代码
没报错没效果
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 13:58:35 | 显示全部楼层
isdkz 发表于 2023-5-20 13:57
从哪里看出来是 snipaste?

从哪里看出来是 snipaste?
文件名
[b]
你那个报错就是这一句引发的呀

我是说,8#里你的代码没报错但是也没效果
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 14:03:41 | 显示全部楼层
[url=forum.php?mod=redirect&goto=findpost&pid=6239230&ptid=228526]isdkz 发表于 2023-5-20 13:59[/url]
没报错应该是找到元素了,找不到也会报错的


8#找到了元素但没效果
  1. ActionChains(self.driver).move_to_element(self.driver.find_element(
  2.             By.XPATH, "//*[@class='iconify iconify--ri']"
  3.         )).perform()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-5-20 14:21:10 | 显示全部楼层
isdkz 发表于 2023-5-20 14:17
你的代码移动到了指定元素,但是并没有包含一个  click()  操作。 perform()  方法只是执行这个链中的所 ...

和刚才一样
程序没有退出,预期在你的代码后面还有操作,可没有执行,当手动关闭窗口时,程序提示你的代码报错,说找不到窗口
  1. E:\Python\e\venv\Scripts\python.exe E:\python\e\main.py
  2. Traceback (most recent call last):
  3.   File "E:\python\e\main.py", line 13, in <module>
  4.     answer = ai.ask(question)
  5.   File "E:\python\e\gpt.py", line 39, in ask
  6.     ActionChains(self.driver).move_to_element(self.driver.find_element(
  7.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 831, in find_element
  8.     return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  9.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
  10.     self.error_handler.check_response(response)
  11.   File "D:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
  12.     raise exception_class(message, screen, stacktrace)
  13. selenium.common.exceptions.WebDriverException: Message: disconnected: unable to send message to renderer
  14.   (failed to check if window was closed: disconnected: not connected to DevTools)
  15.   (Session info: chrome=113.0.5672.127)
  16. Stacktrace:
  17. Backtrace:
  18.         GetHandleVerifier [0x004F8893+48451]
  19.         (No symbol) [0x0048B8A1]
  20.         (No symbol) [0x00395058]
  21.         (No symbol) [0x00386F40]
  22.         (No symbol) [0x003875CA]
  23.         (No symbol) [0x00396F11]
  24.         (No symbol) [0x003974BF]
  25.         (No symbol) [0x00399631]
  26.         (No symbol) [0x003996D0]
  27.         (No symbol) [0x003C00C0]
  28.         (No symbol) [0x003C069B]
  29.         (No symbol) [0x003EDD92]
  30.         (No symbol) [0x003DA304]
  31.         (No symbol) [0x003EC482]
  32.         (No symbol) [0x003DA0B6]
  33.         (No symbol) [0x003B7E08]
  34.         (No symbol) [0x003B8F2D]
  35.         GetHandleVerifier [0x00758E3A+2540266]
  36.         GetHandleVerifier [0x00798959+2801161]
  37.         GetHandleVerifier [0x0079295C+2776588]
  38.         GetHandleVerifier [0x00582280+612144]
  39.         (No symbol) [0x00494F6C]
  40.         (No symbol) [0x004911D8]
  41.         (No symbol) [0x004912BB]
  42.         (No symbol) [0x00484857]
  43.         BaseThreadInitThunk [0x75FB00C9+25]
  44.         RtlGetAppContainerNamedObjectPath [0x773B7B4E+286]
  45.         RtlGetAppContainerNamedObjectPath [0x773B7B1E+238]


  46. 进程已结束,退出代码1
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-16 03:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表