-1

There was a change to the find_element_by_xpath() to find_element(By.Xpath) and now the click is not working.

Code trials:

search_btn = self.driver.find_elements(
    By.XPATH, "//*[@id='viewContainer']/app-listing-container/app-search-container/app-search-form-container/form/div[3]/button[2]").click()
time.sleep(4)
search_btn.click()
time.sleep(5)

Error:

DevTools listening on ws://127.0.0.1:52534/devtools/browser/5aafde31-7b7e-456f-9639-cdfa2bb70678
[16904:17532:0211/180317.139:ERROR:chrome_browser_main_extra_parts_metrics.cc(227)] START: ReportBluetoothAvailability(). If you don't see the END: message, this is crbug.com/1216328.
[16904:17532:0211/180317.140:ERROR:chrome_browser_main_extra_parts_metrics.cc(230)] END: ReportBluetoothAvailability()
[16904:17532:0211/180317.140:ERROR:chrome_browser_main_extra_parts_metrics.cc(235)] START: GetDefaultBrowser(). If you don't see the END: message, this is crbug.com/1216328.
[16904:12228:0211/180317.149:ERROR:device_event_log_impl.cc(214)] [18:03:17.148] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[16904:12228:0211/180317.157:ERROR:device_event_log_impl.cc(214)] [18:03:17.157] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[16904:17532:0211/180317.159:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
Traceback (most recent call last):
  File "C:\!!!Angela\Paid screen scraper\data scraping\data scraping\my_ui_scrapy12.py", line 278, in show_page
    By.XPATH, "//*[@id='viewContainer']/app-listing-container/app-search-container/app-search-form-container/form/div[3]/button[2]").click()
AttributeError: 'list' object has no attribute 'click'
 c:\data scraping\data scraping> [22108:16084:0211/180503.560:ERROR:gpu_init.cc(454)] Passthrough is not supported, GL is disabled, ANGLE is

1 Answer 1

0

find_elements()

find_elements() find elements and returns a list, given a By strategy and locator.

So this line of code:

search_btn = self.driver.find_elements( By.XPATH, "//[@id='viewContainer']/app-listing-container/app-search-container/app-search-form-container/form/div[3]/button[2]")

would return a list and list has no method as click(). Hence the next line:

search_btn.click()

raises the error:

AttributeError: 'list' object has no attribute 'click'

Solution

Replace find_elements() with find_element() you would be good to go.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for that but I still get an error
@VirginiaWalters I'm certainly sure you don't see AttributeError: 'list' object has no attribute 'click' anymore. Can you please confirm?
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='viewContainer']/app-listing-container/app-search-container/app-search-form-container/form/div[3]/button[2]"} (Session info: chrome=98.0.4758.82)
Still getting an error by click error is gone
@VirginiaWalters NoSuchElementException is a different error all together and can be solved as well. Feel free to raise a new question with your new requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.