From 8fffb5a208f3e2776f69dc15a0538ddf165f8f81 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: Wed, 29 Mar 2023 21:28:15 -0600 Subject: [PATCH] fix: use current selenium api I tried the demo and it failed saying, "AttributeError: 'WebDriver' object has no attribute 'find_element_by_tag_name'" It looks like the deprecated `find_element_by_*` methods have been removed in Selenium 4.3.0. This commit replaces all the usages of those deprecated methods with their current alternatives. Refs: https://stackoverflow.com/a/72773269/5432315 --- PageObjectLibrary/__init__.py | 2 +- PageObjectLibrary/pageobject.py | 3 ++- doc/pageobjectlibrary.html | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/PageObjectLibrary/__init__.py b/PageObjectLibrary/__init__.py index 553632c..1c785a2 100644 --- a/PageObjectLibrary/__init__.py +++ b/PageObjectLibrary/__init__.py @@ -54,7 +54,7 @@ class your keywords have access to the following pre-defined standard Selenium methods provided by the Selenium library. The following example shows how to find all link elements on a page: - | elements = self.browser,find_elements_by_tag_name("a") + | elements = self.browser.find_elements(By.TAG_NAME, "a") = Creating Page Object Classes = diff --git a/PageObjectLibrary/pageobject.py b/PageObjectLibrary/pageobject.py index b6df59d..9b55bc0 100644 --- a/PageObjectLibrary/pageobject.py +++ b/PageObjectLibrary/pageobject.py @@ -9,6 +9,7 @@ from selenium.webdriver.support.expected_conditions import staleness_of from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.common.by import By import six @@ -91,7 +92,7 @@ def _wait_for_page_refresh(self, timeout=10): 2) the javascript document.readyState variable to be set to "complete" """ - old_page = self.browser.find_element_by_tag_name('html') + old_page = self.browser.find_element(By.TAG_NAME, 'html') yield WebDriverWait(self.browser, timeout).until( staleness_of(old_page), diff --git a/doc/pageobjectlibrary.html b/doc/pageobjectlibrary.html index d688e9d..b064d15 100644 --- a/doc/pageobjectlibrary.html +++ b/doc/pageobjectlibrary.html @@ -548,7 +548,7 @@ jQuery.extend({highlight:function(e,t,n,r){if(e.nodeType===3){var i=e.data.match(t);if(i){var s=document.createElement(n||"span");s.className=r||"highlight";var o=e.splitText(i.index);o.splitText(i[0].length);var u=o.cloneNode(true);s.appendChild(u);o.parentNode.replaceChild(s,o);return 1}}else if(e.nodeType===1&&e.childNodes&&!/(script|style)/i.test(e.tagName)&&!(e.tagName===n.toUpperCase()&&e.className===r)){for(var a=0;a