0

estoy recien empezando a programar en python con algunos tutoriales y cursos con el webdriver de Edge, estoy desarrollando de prueba un bot para un juego, pero lo que quiero es que haga la función mientras tenga un 20 porcentaje o 20 de energia en una barra, cuando este a menos de 20 se detenga el bot. Este es mi código hasta ahora. Agradecería la ayuda! :)

    import time

from msedge.selenium_tools import Edge, EdgeOptions

options = EdgeOptions()
options.use_chromium = True
driver = Edge(options=options)
driver.get("https://....com/")
driver.maximize_window()
url="https://...."
time.sleep(2)
#entrar
entrar = driver.find_element_by_xpath("//*[@id='menuHead']/li[4]")
entrar.click()
text1 = driver.find_element_by_xpath("//*[@id='loginForm']/table/tbody/tr[1]/td[2]/input")
text1.send_keys("User")
time.sleep(1)
text2 = driver.find_element_by_xpath("//*[@id='loginForm']/table/tbody/tr[2]/td[2]/input")
text2.send_keys("Password")
time.sleep(1)
iniciar=driver.find_element_by_xpath("//*[@id='loginForm']/table/tbody/tr[4]/td[2]/input")
iniciar.click()
time.sleep(3)
#Pagina de
while driver.find_element_by_xpath("//*[@id='infobar_energy']/div[2]/div"):
    try:
        driver.get(url)
        time.sleep(2)
        atack1=driver.find_element_by_xpath("//*[@id='humanHuntResult']/div[2]/div[2]/table/tbody/tr/td[2]/div/div/button")
        atack1.click()
        time.sleep(2)
        atack2=driver.find_element_by_xpath("//*[@id='content']/div[2]/div/a")
        atack2.click()
    finally:
        time.sleep(1)

He realizado una pequeña modificación con respecto a una ayuda:

caza = driver.find_element_by_xpath("//*[@id='infobar_energy']/div[2]")
caza = float(caza)
if (caza<=55):
        driver.get(url)
        time.sleep(2)
        atack1=driver.find_element_by_xpath("//*[@id='infobar_energy']/div[2]")
        atack1.click()
        time.sleep(2)
        atack2=driver.find_element_by_xpath("//*[@id='content']/div[2]/div/a")
        atack2.click()

Pero aun no consigo, obtengo un error: TypeError: float() argument must be a string or a number, not 'WebElement'

Estas son algunas imágenes para referenciar el elemento Codigo HTML

Progressbar

1 respuesta 1

0

Hola lo que podrias hacer es obtener el valor de la etiqueta html donde esta la vida y luego en cada iteracion analizarla, por ejemplo

vida = driver.find_element_by_xpath('') #aqui se debe obtener el valor de la vida en string
vida = float(vida) #con esto convertivos el string en un flotante 
if (vida <= 20):
    break #con esto rompemos el bucle

espero te sea de ayuda

1
  • Muchas gracias por tu ayuda, he realizado algunos cambios en el código pero no consigo hacerlo funcionar, acabo de actualizar el post por si sirve algo de referencia.
    – Yafel GH
    el 11 mar. 2021 a las 21:40

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.