简体   繁体   English

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素:{“方法”:“css选择器”,“选择器”:“.ui流感~”}

[英]selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui flu~"}

This is the code I use:这是我使用的代码:

import requests as r, sys as sus, bs4 as bs, webbrowser as wb
from selenium import webdriver as wd

dr = wd.Chrome()

b = r.get("https://uupdump.net/fetchupd.php?arch=amd64&ring=wif&build=latest").text
s = bs.BeautifulSoup(b, features="html.parser")

if "/selectlang.php?id=" in b:
    l = b.split("/selectlang.php?id=")[1].split('"')[0]
    u = f"https://uupdump.net/download.php?id={l}&pack=es-es&edition=professional"
    print(u)
    b = r.get(u).text
    s = bs.BeautifulSoup(b, features="html.parser")
    print(s)
    dr.get(u)
    b = dr.find_element_by_class_name('ui fluid right labeled icon primary button')

And this is the error:这是错误:

uupdump.py:17: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  b = dr.find_element_by_class_name('ui fluid right labeled icon primary button')
Traceback (most recent call last):
  File "C:\Users\Aritz\Downloads\thign\uupdump.py", line 17, in <module>
    b = dr.find_element_by_class_name('ui fluid right labeled icon primary button')
  File "C:\Users\Aritz\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 760, in find_element_by_class_name
    return self.find_element(by=By.CLASS_NAME, value=name)
  File "C:\Users\Aritz\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\Aritz\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Aritz\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".ui fluid right labeled icon primary button"}
  (Session info: chrome=98.0.4758.82)
Stacktrace:
Backtrace:
        Ordinal0 [0x00BF7AC3+2587331]
        Ordinal0 [0x00B8ADD1+2141649]
        Ordinal0 [0x00A83BB8+1063864]
        Ordinal0 [0x00AB01CE+1245646]
        Ordinal0 [0x00AB03CB+1246155]
        Ordinal0 [0x00ADA612+1418770]
        Ordinal0 [0x00AC86D4+1345236]
        Ordinal0 [0x00AD8A0A+1411594]
        Ordinal0 [0x00AC84A6+1344678]
        Ordinal0 [0x00AA53F6+1201142]
        Ordinal0 [0x00AA62E6+1204966]
        GetHandleVerifier [0x00D9DF22+1680738]
        GetHandleVerifier [0x00E50DBC+2413564]
        GetHandleVerifier [0x00C8D151+563089]
        GetHandleVerifier [0x00C8BF13+558419]
        Ordinal0 [0x00B9081E+2164766]
        Ordinal0 [0x00B95508+2184456]
        Ordinal0 [0x00B95650+2184784]
        Ordinal0 [0x00B9F5BC+2225596]
        BaseThreadInitThunk [0x764A6739+25]
        RtlGetFullPathName_UEx [0x76F98AFF+1215]
        RtlGetFullPathName_UEx [0x76F98ACD+1165]

What I want is to use selenium to find a button by its class name from uupdump.net , to download the latest version zip file.我想要的是使用seleniumuupdump.net通过其 class 名称找到一个按钮,以下载最新版本的 zip 文件。

Help.帮助。

[HTML button image] [HTML 按钮图像]

What else to say?还有什么好说的? "It looks like your post is mostly code" “看起来你的帖子主要是代码”

To find the specific button element that you want you can do:要找到您想要的特定按钮元素,您可以执行以下操作:

b = dr.find_elements_by_class_name('primary')[-1]

instead of代替

b = dr.find_element_by_class_name('ui fluid right labeled icon primary button')

Because the class name that you copied is a compilation of classnames for that object.因为您复制的 class 名称是该 object 的类名的汇编。 Each class name is separated by a space.每个 class 名称由空格分隔。 Therefore using the most unique identifier 'primary' we are able to narrow the elements down to 3 and see that the element that you want is the last one.因此,使用最独特的标识符“primary”,我们能够将元素缩小到 3 个,并看到您想要的元素是最后一个。

and then do然后做

b.click()

to click on that element.单击该元素。

Though you may want to wait for that element to load on the page.尽管您可能希望等待该元素加载到页面上。

As per the HTML:根据 HTML:

HTML

To identify the clickable element with text as Create download package you can use either of the following Locator Strategies :要将带有文本的可点击元素标识为创建下载 package ,您可以使用以下任一定位器策略

  • Using xpath :使用xpath

     b = dr.find_element(By.XPATH, "//button[@class='ui fluid right labeled icon primary button' and contains(., 'Create download package')]")

Ideally to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :理想情况下,单击您需要为element_to_be_clickable()诱导WebDriverWait的元素,您可以使用以下任一Locator Strategies

  • Using XPATH :使用XPATH

     b = WebDriverWait(dr, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='ui fluid right labeled icon primary button' and contains(., 'Create download package')]")))
  • Note : You have to add the following imports:注意:您必须添加以下导入:

     from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC

暂无
暂无

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

相关问题 selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{&quot;method&quot;:&quot;xpath&quot;,&quot;selector&quot;:&quot;&quot;} - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":""} selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素: - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素: - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试使用硒单击“下一步”按钮时无法定位元素 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium 硒:selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素: - Selenium: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法通过 Python 使用 Selenium 定位元素错误 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element error using Selenium through Python Python Selenium 检查复选框:selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素 - Python Selenium checking checkbox: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element Python Selenium Webdriver selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素 - Python Selenium Webdriver selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法使用带有Python的Selenium ChromeDriver Chrome找到元素 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element using Selenium ChromeDriver Chrome with Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM