Kann jemand über den Python Code gucken?

Der Dateipfad ist definitiv richtig. Ich habe versucht, das Bild direkt in den Ordner der Python-Datei zu legen. Trotzdem tritt weiterhin der gleiche Fehler auf. Das Bild ist im richtigen Format, und ich habe keine Ahnung, was das Problem verursacht.

import logging
import pyautogui


class Coordinates:
    def __init__(self, function, image_name, confidence=0.9, region=None):
        self.function = function
        self.image_name = image_name
        self.confidence = confidence
        self.region = region


    def offset(self, x_offset=0, y_offset=0, width_offset=0, height_offset=0):
        try:
            image_path = fr'templates\{self.image_name}.png'
            location = self.function(image_path, confidence=self.confidence, region=self.region)         
            
            if len(location) == 2:
                x, y = location
                x += x_offset
                y += y_offset
                return x, y


            elif len(location) == 4:
                x, y, width, height = location
                x += x_offset
                y += y_offset
                width += width_offset
                height += height_offset
                return x, y, width, height
            
        except pyautogui.ImageNotFoundException as e:
            logging.error(f'{e}')
            return None
        
x = Coordinates(pyautogui.locateCenterOnScreen, 'test').offset()


print(x)

Bild zum Beitrag
Computer, Programmiersprache, Python, Python 3
Wie klicke ich auf diese Elemente mit Python und Selenium?

Hallo,

Ich versuche, auf die folgenden Elemente auf dieser Webseite (https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx) mit Python und Selenium zu klicken.

//*[@id=“tone-options”]/li[3]/button

//*[@id=“camera-container”]/button

//*[@id=“camera-container”]/cib-flyout/cib-visual-search//div[3]/button[1]

Ich habe XPATH, CSS probiert.

Fehler:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="tone-options"]/li[3]/button"}

 (Session info: chrome=119.0.6045.200)

Stacktrace:

GetHandleVerifier [0x00007FF7D97B82B2+55298]

(No symbol) [0x00007FF7D9725E02]

(No symbol) [0x00007FF7D95E05AB]

(No symbol) [0x00007FF7D962175C]

(No symbol) [0x00007FF7D96218DC]

(No symbol) [0x00007FF7D965CBC7]

(No symbol) [0x00007FF7D96420EF]

(No symbol) [0x00007FF7D965AAA4]

(No symbol) [0x00007FF7D9641E83]

(No symbol) [0x00007FF7D961670A]

(No symbol) [0x00007FF7D9617964]

GetHandleVerifier [0x00007FF7D9B30AAB+3694587]

GetHandleVerifier [0x00007FF7D9B8728E+4048862]

GetHandleVerifier [0x00007FF7D9B7F173+4015811]

GetHandleVerifier [0x00007FF7D98547D6+695590]

(No symbol) [0x00007FF7D9730CE8]

(No symbol) [0x00007FF7D972CF34]

(No symbol) [0x00007FF7D972D062]

(No symbol) [0x00007FF7D971D3A3]

BaseThreadInitThunk [0x00007FF8125E7344+20]

RtlUserThreadStart [0x00007FF8130026B1+33]

kann mir jemand helfen? Danke.

HTML, Webseite, CSS, HTML5, Code, PHP, Programmiersprache, Python, Webdesign, Webentwicklung, Frontend, Python 3, Selenium

Meistgelesene Beiträge zum Thema Python