I am making an automated JKLM bomb party bot using selenium.py (prank my friends). When it is given a link to a private JKLM, it will go there, confirm the username, but then get stuck on the “join game” button (I get TimeoutException Error).
driver = webdriver.Safari()
driver.get(link)
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div[3]/form/div[2]/input")))
element.submit()
element1 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[@class='styled joinRound']")))
element1.click()
I have tried Absolute XPath:
/html/body/div[2]/div[3]/div[1]/div[1]/button
Relative XPATH:
//button[@class='styled joinRound’]
And Class Name:
styled joinRound
Along with Tag Name and CSS selector.
Any help would be greatly appreciated. HTML I am trying to access and click on:
<button data-text="joinGame">Join game</button>
CodePudding user response:
I believe you may need to switch to the iframe first in Selenium. I had success with this:
import selenium.webdriver
def main():
driver = selenium.webdriver.Firefox()
driver.get('https://jklm.fun/DKCY')
driver.switch_to_frame(0)
xpath = '//div[@]/div[@]/button'
els = driver.find_elements_by_xpath(xpath)
if els is None or len(els) == 0:
print('failed to find element')
return
els[0].click()
if __name__ == '__main__':
main()
See:
