I'm not sure if im using the right method to click what i'm trying to click right now. I am trying to click on 'battling' and then subsequently the appropriate type of animal to kill after that.
import autogui, sys, time, webbrowser, selenium
import undetected_chromedriver.v2 as uc
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common import action_chains
from selenium.webdriver.common.by import By
#Open Browser and visit website.
driver = uc.Chrome()
driver.get('https://www.iqrpg.com/game.html')
time.sleep(5)
#Complete username and password fields Login
userN = 'seltest'
passW = 'seltest'
driver.find_element(By.NAME, "login_username").send_keys(userN)
driver.find_element(By.NAME, "login_password").send_keys(passW Keys.ENTER)
time.sleep(2)
#find Battling and click to begin fight
driver.find_element(By.CLASS_NAME("Battling")).Click();
The inspect element for what i am trying to click on is as follows:
<a data-v-ae2d03a4="" href="/areas" >Battling</a>
typeerror: str object is not callable
tried a lot of out dated and in date web element searches, i've also tried calling upon 'a', 'area's, the link itself to /areas, a tonne of stuff, i just dont know what i'm doing it seems
CodePudding user response:
Battling
is not a class name. It's a text content.
You can locate that element by following ways:
driver.find_element(By.XPATH,"//a[contains(text(),'Battling')]")).click()
Or
driver.find_element(By.XPATH,"//a[@href='/areas']")).click()
Also, dont mix other languages styles. I see all your code here is in Python while .Click();
is C#
style...
CodePudding user response:
You can try the following, with By.LINK_TEXT
:
driver.find_element(By.LINK_TEXT('Battling')).click()
The error 'str' object is not callable
appear because this line code:
driver.find_element(By.CLASS_NAME("Battling")).Click();
It's wrong patterrn to find element method in python style.