Can you tell me why at this website: https://pasja-informatyki.pl/programowanie-webowe/test/przeglad-html/ I have no idea why it's not clicking the button. Maybe the alert after clicking is messing with selenium? I tried differend selectors and didn't work. I hope someone can help me :D
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import os
class Bot:
def __init__(self):
self.driver = webdriver.Firefox()
self.action = ActionChains(self.driver)
self.driver.maximize_window()
self.driver.get("https://pasja-informatyki.pl/programowanie-webowe/test/przeglad-html/")
sleep(1)
x = 1
self.driver.find_element_by_id("hcks").click()
for x in range (10):
#pytanie = self.driver.find_element_by_partial_link_text(f"{x+1}.").text
pytanie = self.driver.find_element_by_xpath(f"//div[contains(text(),'{x+1}.')]").text
f = open("pio.txt", "a")
f.write(pytanie + "\n")
f.close()
self.driver.find_element_by_id(f"odpa{x+1}").click();
self.driver.execute_script("window.scrollTo(0, 500)")
self.driver.execute_script("window.scrollTo(0, 3500)")
sleep(1)
self.driver.execute_script("arguments[0].click();", WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-large#sprawdz"))))
self.driver.find_element_by_xpath("//*[@id='przycisk']").click()
#self.action.move_to_element(przycisk).click(sprawdz).perform()
self.driver.find_element_by_xpath("//button[@id='sprawdz']").click();
#self.driver.find_element_by_link_text("ok").click();
for x in range (10):
odpowiedz = self.driver.find_element_by_xpath(f"//div[contains(text(),'odp{x+1}') and @class='odpgood']").text
f = open("pio.txt", "a")
f.write(odpowiedz + "\n")
f.close()
Bot()