Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: stop using removed webdriver find_by methods #78

Merged
merged 1 commit into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions finance_dl/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def invoice_finder():
By.XPATH, '//a[contains(@href, "orderID=")]')
else:
# order summary link is hidden in submenu for each order
elements = self.driver.find_elements_by_xpath(
elements = self.driver.find_elements(By.XPATH,
'//a[@class="a-popover-trigger a-declarative"]')
return [a for a in elements if a.text == self.domain.invoice]

Expand Down Expand Up @@ -389,7 +389,7 @@ def invoice_link_finder_hidden():
# submenu containing order summary takes some time to load after click
# search for order summary link and compare order_id
# repeat until order_id is different to last order_id
summary_links = self.driver.find_elements_by_link_text(
summary_links = self.driver.find_elements(By.LINK_TEXT,
self.domain.order_summary)
if summary_links:
href = summary_links[0].get_attribute('href')
Expand Down
4 changes: 2 additions & 2 deletions finance_dl/comcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_bills_link():
pass
bills_link = get_bills_link()

self.driver.find_element_by_tag_name('body').send_keys(Keys.ESCAPE)
self.driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ESCAPE)
bills_link.click()

def get_links():
Expand All @@ -168,7 +168,7 @@ def get_links():
cur_el = link
bill_date = None
while True:
parent = cur_el.find_element_by_xpath('..')
parent = cur_el.find_element(By.XPATH, '..')
if parent == cur_el:
break
try:
Expand Down
5 changes: 3 additions & 2 deletions finance_dl/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def CONFIG_discover():
import os
import shutil
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from . import scrape_lib
Expand Down Expand Up @@ -85,11 +86,11 @@ def check_after_wait(self):
check_url(self.driver.current_url)

def find_account_last4(self):
return self.driver.find_element_by_xpath(XPATH_OF_LAST_FOUR_DIGITS).text
return self.driver.find_element(By.XPATH, XPATH_OF_LAST_FOUR_DIGITS).text

def login(self):
try:
account = self.driver.find_element_by_xpath(XPATH_OF_LAST_FOUR_DIGITS)
account = self.driver.find_element(By.XPATH, XPATH_OF_LAST_FOUR_DIGITS)
logger.info("Already logged in")
except NoSuchElementException:
logger.info('Initiating log in')
Expand Down
12 changes: 6 additions & 6 deletions finance_dl/scrape_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def all_conditions(*conditions):


def extract_table_data(table, header_names, single_header=False):
rows = table.find_elements_by_xpath('thead/tr | tbody/tr | tr')
rows = table.find_elements(By.XPATH, 'thead/tr | tbody/tr | tr')
headers = []
seen_data = False
data = []
for row in rows:
cell_elements = row.find_elements_by_xpath('th | td')
cell_elements = row.find_elements(By.XPATH, 'th | td')
cell_values = [x.text.strip() for x in cell_elements]
is_header_values = [x in header_names for x in cell_values if x]
if len(is_header_values) == 0:
Expand Down Expand Up @@ -217,7 +217,7 @@ def get_downloaded_file(self):
# See http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html
@contextlib.contextmanager
def wait_for_page_load(self, timeout=30):
old_page = self.driver.find_element_by_tag_name('html')
old_page = self.driver.find_element(By.TAG_NAME, 'html')
yield
WebDriverWait(self.driver, timeout).until(
expected_conditions.staleness_of(old_page),
Expand Down Expand Up @@ -355,7 +355,7 @@ def find_visible_elements_by_descendant_partial_text(

def find_elements_by_descendant_partial_text(self, text, element_name,
only_displayed=False):
all_elements = self.driver.find_elements_by_xpath(
all_elements = self.driver.find_elements(By.XPATH,
"//text()[contains(.,%r)]/ancestor::*[self::%s][1]" %
(text, element_name))
if only_displayed:
Expand All @@ -364,15 +364,15 @@ def find_elements_by_descendant_partial_text(self, text, element_name,

def find_elements_by_descendant_text_match(self, text_match, element_name,
only_displayed=False):
all_elements = self.driver.find_elements_by_xpath(
all_elements = self.driver.find_elements(By.XPATH,
"//text()[%s]/ancestor::*[self::%s][1]" % (text_match,
element_name))
if only_displayed:
return [x for x in all_elements if is_displayed(x)]
return all_elements

def find_visible_elements_by_partial_text(self, text, element_name):
all_elements = self.driver.find_elements_by_xpath(
all_elements = self.driver.find_elements(By.XPATH,
"//%s[contains(.,%r)]" % (element_name, text))
return [x for x in all_elements if is_displayed(x)]

Expand Down
10 changes: 5 additions & 5 deletions finance_dl/usbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def login(self):
def find_account_link_in_any_frame(self):
for frame in self.for_each_frame():
try:
return self.driver.find_element_by_partial_link_text(self.account_name)
return self.driver.find_element(By.PARTIAL_LINK_TEXT, self.account_name)
except:
pass
raise NoSuchElementException()
Expand All @@ -155,7 +155,7 @@ def find_account_link_in_any_frame(self):
def find_download_page_in_any_frame(self):
for frame in self.for_each_frame():
try:
return self.driver.find_element_by_partial_link_text("Download Transactions")
return self.driver.find_element(By.PARTIAL_LINK_TEXT, "Download Transactions")
except:
pass
raise NoSuchElementException()
Expand All @@ -164,8 +164,8 @@ def find_download_page_in_any_frame(self):
def find_date_fields(self):
for frame in self.for_each_frame():
try:
fromDate = self.driver.find_element_by_id("FromDateInput")
toDate = self.driver.find_element_by_id("ToDateInput")
fromDate = self.driver.find_element(By.ID, "FromDateInput")
toDate = self.driver.find_element(By.ID, "ToDateInput")
return (fromDate, toDate)
except:
pass
Expand All @@ -175,7 +175,7 @@ def find_date_fields(self):
def find_download_link(self):
for frame in self.for_each_frame():
try:
return self.driver.find_elements_by_id("DTLLink")[0]
return self.driver.find_elements(By.ID, "DTLLink")[0]
except:
pass
raise NoSuchElementException()
Expand Down