2

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"}

I want to use Selenium to find a button by its class name from uupdump.net, to download the latest version zip file.

Screenshot:

[HTML button image]

aritz331_
  • 68
  • 2
  • 9
  • error is because you are using way to many identifiers for the class name. Instead, you should try to limit it down to one of the class names (each identifier separated by a space is a different class name). Try and find a specific class name that is used for your button or else you will have to use a different method to find your button (not by classname) – Andrew Ryan Feb 04 '22 at 18:20
  • Or use css selectors with . between each class name. – Arundeep Chohan Feb 04 '22 at 18:31
  • 1
    Hi there. The edit from @undetectedSelenium was a good one - please leave it be. There's no need to add commentary on the editing process into questions - if you think the editing process needs adjustment then _Meta Stack Overflow_ is the best place for that. Thanks! – halfer Feb 19 '22 at 21:50

3 Answers3

2

As per the HTML:

HTML

To identify the clickable element with text as Create download package you can use either of the following Locator Strategies:

  • Using 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:

  • Using 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1

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. Each class name is separated by a space. 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.

and then do

b.click()

to click on that element.

Though you may want to wait for that element to load on the page.

Andrew Ryan
  • 1,489
  • 3
  • 15
  • 21
0

In all such conditions you need to include/increase the wait time statement , so that the webpage is fully loaded in browser.

For my scenario the time.sleep() was not present, I added it and then gradually increased the time to 60sec and the error was resolved. Below is the copy of error I got

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="performance"]/div[1]/div[1]/div[1]/a/div[2]"}
  (Session info: headless chrome=112.0.5615.138)
Ashish Tripathi
  • 301
  • 3
  • 3