Код: Выделить всё
alskndafnsgkmsgn
Help
slkdgj slgh ;iszj g;jz;x
Файл Python выглядит следующим образом:
Код: Выделить всё
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from pprint import pprint
import time
def highlight( element):
"""Highlights a Selenium WebDriver element to indicate successful selector targeting."""
driver = element._parent
def apply_style(s):
driver.execute_script("arguments[0].setAttribute('style', arguments[1]);", element, s)
original_style = element.get_attribute('style')
count = 0
colors = ['yellow', 'red']
while count < 10:
if ((count % 2) == 0):
background = colors[0]
border = colors[1]
else:
background = colors[1]
border = colors[0]
apply_style("background: %s; border: 2px solid %s;" % (background, border))
time.sleep(0.2)
count += 1
apply_style(original_style)
url = "file:////test.html"
options = Options()
firefox_profile = FirefoxProfile()
firefox_profile.set_preference("javascript.enabled", False)
options.profile = firefox_profile
driver = webdriver.Firefox(options=options)
pprint(driver.capabilities)
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
driver.get( url )
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Help"]')))
element.click() # This command waits until the element is ready for clicking.
highlight ( element )
element.click()
Вывод следующий:
Код: Выделить всё
./test.py
/test.py:40: DeprecationWarning: firefox_profile has been deprecated, please use an Options object
firefox_profile = FirefoxProfile()
/test.py:42: DeprecationWarning: Setting a profile has been deprecated. Please use the set_preference and install_addons methods
options.profile = firefox_profile
{'acceptInsecureCerts': True,
'browserName': 'firefox',
'browserVersion': '148.0.2',
'moz:accessibilityChecks': False,
'moz:buildID': '20260309231353',
'moz:geckodriverVersion': '0.36.0',
'moz:headless': False,
'moz:platformVersion': '6.8.0-101-generic',
'moz:processID': 1196767,
'moz:profile': '/tmp/rust_mozprofileOYDFl5',
'moz:shutdownTimeout': 60000,
'moz:webdriverClick': True,
'moz:windowless': False,
'pageLoadStrategy': 'normal',
'platformName': 'linux',
'proxy': {},
'setWindowRect': True,
'strictFileInteractability': False,
'timeouts': {'implicit': 0, 'pageLoad': 300000, 'script': 30000},
'unhandledPromptBehavior': 'dismiss and notify',
'userAgent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:148.0) '
'Gecko/20100101 Firefox/148.0'}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Прошу прощения, но теперь я решил проблему!
Комментирование firefox_profile.set_preference("javascript.enabled", False)
работало в примере, но в моем реальном коде это заблокировало всплывающее окно cookie, поэтому я собирался исследовать по-другому.
Тогда я подумал, что посмотрю на вопрос об устаревших параметрах - и, поскольку это были предупреждения, я решил проигнорировать их, чтобы код заработал.
Я обновил geckodriver с 0,26 до 0,36 и убедился, что использую Selenium 4.41.0.
Теперь я получаю сообщение об ошибке OSError: [Errno 8] Ошибка формата Exec: '//geckodriver'.
Расположение драйвера находится в моем PATH, и, прочитав, я увидел, что это означает, что я использую неправильный драйвер geckodriver для своего компьютера.
Я попробовал geckodriver-v0.36.0-linux64.tar.gz , который, как я полагаю, подходит для мой ноутбук на базе процессора Intel.
Затем я попытался вернуться к драйверу geckodriver 0.26, и это тоже не сработало.
Затем я перешел в соответствующий каталог и набрал geckodriver -V для версии 0.26, и получил отчет с этой версией.
Когда я попробовал то же самое для версии 0.36, я получил:-
Код: Выделить всё
bash: /
/geckodriver: cannot execute binary file: Exec format error
Поэтому я продвинулся немного вперед, но не для того, чтобы я мог выполнить ни свой оригинальный Python, ни тестовый сценарий.
Любая помощь будет очень признательна (и спасибо за всю помощь).>
Подробнее: https://stackoverflow.com/questions/799 ... em-to-work
Мобильная версия