Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Using Selenium to locate element

$
0
0

Using this site:(https://buyee.jp/mercari/search?keyword=seiko%20S-212&status=on_sale), I'm trying to locate the element that has the value: "Items 1 to 2", please see screenshot below:

I tried locating the element by xpath, my full code:

from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byval = 'https://buyee.jp/mercari/search?keyword=seiko%20S-212&status=on_sale'driver = webdriver.Firefox()driver.get(val)wait = WebDriverWait(driver, 10)items = driver.find_element(By.XPATH, '/html/body/div/div/div/div/div[2]/div[2]')

However I get the following errors:

Traceback (most recent call last):  File "/home/kali/PycharmProjects/pythonProject/auto.py", line 10, in <module>    items = driver.find_element(By.XPATH, '/html/body/div/div/div/div/div[2]/div[2]')            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/kali/PycharmProjects/pythonProject/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 741, in find_element    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/kali/PycharmProjects/pythonProject/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute    self.error_handler.check_response(response)  File "/home/kali/PycharmProjects/pythonProject/.venv/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response    raise exception_class(message, screen, stacktrace)selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div/div/div/div/div[2]/div[2]; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exceptionStacktrace:RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8WebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:187:5NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:505:5element.find/</<@chrome://remote/content/marionette/element.sys.mjs:135:16Process finished with exit code 1

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>