• Почему не нажимается кнопка Selenium?

    mirniycruxix
    @mirniycruxix Автор вопроса
    Решение оказалось в том, что в цикле перед continue в конце нужно было поставить
    driver.execute_script("document.getElementsByClassName('button_to_click')[0].click();")
    То есть итоговый код получился такой:
    import requests
    import time
    
    import selenium
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.keys import Keys
    from selenium.common.exceptions import NoSuchElementException
    
    link = "https://site.ru/"
    
    driver = webdriver.Firefox(executable_path = r'D:/Apps/Geckodriver/geckodriver.exe')
    driver.get(link)
    
    while True:
        try:
            number = driver.find_element(By.CLASS_NAME, 'element_to_find')
            break
        except NoSuchElementException:
            driver.execute_script("document.getElementsByClassName('button_to_click')[0].click();")
            continue
    
    result = driver.find_element(By.CLASS_NAME, 'element_to_find').text.replace(" ","")
    print(result)
    Ответ написан
    Комментировать
  • Как сделать размытый фон карточки не размывая контент внутри?

    mirniycruxix
    @mirniycruxix
    backdrop-filter: blur(12px); блоку, фон которого хочешь сделать размытым
    Ответ написан
  • Не изменяется файл .htaccess?

    mirniycruxix
    @mirniycruxix Автор вопроса
    Все оказалось намного проще. Помог перезапуск Apache.
    Ответ написан
    Комментировать
  • Добавить класс к div в коде JS?

    mirniycruxix
    @mirniycruxix
    Добавьте строчку newElement.classList.add('Class');, где Class - имя вашего класса.

    var downloadButton = document.getElementById("download");
    var counter = 10;
    var newElement = document.createElement("div");
    newElement.innerHTML = "You can download the file in 10 seconds.";
    var id;
    
    newElement.classList.add('Class');
    
    downloadButton.parentNode.replaceChild(newElement, downloadButton);
    
    id = setInterval(function() {
        counter--;
        if(counter < 0) {
            newElement.parentNode.replaceChild(downloadButton, newElement);
            clearInterval(id);
        } else {
            newElement.innerHTML = "You can download the file in " + counter.toString() + " seconds.";
        }
    },  1000);
    Ответ написан
    1 комментарий