Amazon gift card reload fails with unable to locate element error
cy11100 opened this issue · comments
When I ran the code earlier, the script failed with the error:
v2.0.3-dev Windows Traceback (most recent call last):
File "debbit.py", line 294, in web_automation_wrapper
result = merchant.web_automation(driver, merchant, amount)
File "xxx\debbit\src\program_files\merchants\amazon_gift_card_reload.py", line 152, in web_automation
driver.find_element_by_xpath("//button[starts-with(text(),'Reload') and contains(text(),'" + utils.cents_to_str(amount) + "')]").click()
File "xxx\src-hO995slM\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "xxx\src-hO995slM\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "xxx\src-hO995slM\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "xxx\src-hO995slM\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //button[starts-with(text(),'Reload') and contains(text(),'0.58')]
There may have been some Amazon code change which only updated the final button after the amount field loses focus. The issue was fixed by adding 2 lines to the code before for element in driver.find_elements_by_xpath("//span[contains(text(),'ending in " + merchant.card[-4:] + "')]"):
:
driver.find_element_by_id('asv-manual-reload-amount').send_keys(Keys.ENTER)
time.sleep(1 + random.random() * 2)