Python Selenium

Merhabalar,
Python selenium ile bir websitesini açmak ve web sitesindeki searchboxa ulaşmak istiyorum. Xpath ve türlülerini defalarca denememe rağmen bir türlü başaramadım.
Aşağıda kodu, html kısmını ve hatayı ekliyorum. Lütfen yardımcı olabilir misiniz.

Kod:
search_box = browser.find_element(By.XPATH, “(//input[@placeholder=‘Search coin, pair, contract address, exchange, or post’])[1]”)

html search box:

Aldığım hata:
search_box = browser.find_element(By.XPATH, “(//input[@placeholder=‘Search coin, pair, contract address, exchange, or post’])[1]”)
File “C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 742, in find_element
return self.execute(Command.FIND_ELEMENT, {“using”: by, “value”: value})[“value”]
File “C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 348, in execute
self.error_handler.check_response(response)
File “C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:“xpath”,“selector”:“(//input[@placeholder=‘Search coin, pair, contract address, exchange, or post’])[1]”}
(Session info: chrome=120.0.6099.130); For documentation on this error, please visit: Understanding Common Errors | Selenium
Stacktrace:
GetHandleVerifier [0x00007FF62B842142+3514994]
(No symbol) [0x00007FF62B460CE2]
(No symbol) [0x00007FF62B3076AA]
(No symbol) [0x00007FF62B351860]
(No symbol) [0x00007FF62B35197C]
(No symbol) [0x00007FF62B394EE7]
(No symbol) [0x00007FF62B37602F]
(No symbol) [0x00007FF62B3928F6]
(No symbol) [0x00007FF62B375D93]
(No symbol) [0x00007FF62B344BDC]
(No symbol) [0x00007FF62B345C64]
GetHandleVerifier [0x00007FF62B86E16B+3695259]
GetHandleVerifier [0x00007FF62B8C6737+4057191]
GetHandleVerifier [0x00007FF62B8BE4E3+4023827]
GetHandleVerifier [0x00007FF62B5904F9+689705]
(No symbol) [0x00007FF62B46C048]
(No symbol) [0x00007FF62B468044]
(No symbol) [0x00007FF62B4681C9]
(No symbol) [0x00007FF62B4588C4]
BaseThreadInitThunk [0x00007FF9A7AD257D+29]
RtlUserThreadStart [0x00007FF9A988AA58+40]

Class ile placeholder ile ve input ile denedim hepsinde aynı hatayı alıyorum

bkz: Soru Sorarken Sıkça Düşülen Hatalar #1, #6 ve #7

Öncelikle kusura bakmayın, düzeltip gönderiyorum.

Kod:

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

browserOpts = webdriver.ChromeOptions()
#browserOpts.add_argument("--incognito")
#browserOpts.add_argument("--headless")
browserOpts.browser_version = "stable"
browserPrefs = {"credentials_enable_service": False, "profile.password_manager_enabled": False}
browserOpts.add_experimental_option("excludeSwitches", ["enable-automation", "enable-logging"])
browserOpts.add_experimental_option("prefs", browserPrefs)
browserOpts.add_argument("--disable-single-click-autofill")
browserOpts.add_argument("--disable-gpu")
browserOpts.add_argument("--blink-settings=imagesEnabled=false")
browserOpts.set_capability("goog:loggingPrefs", {"performance": "ALL"})

browser = webdriver.Chrome(options=browserOpts)
browser.get("https://coinmarketcap.com/")
browser.maximize_window()
time.sleep(15)

search_box = browser.find_element(By.XPATH, "(//input[@placeholder='Search coin, pair, contract address, exchange, or post'])[1]")

search_query = 'aramayı yaz inputa çevirebilirsin'  # Aramak istediğiniz veriyi buraya girin
search_box.send_keys(search_query)
#search_box.send_keys(Keys.RETURN)

wait = WebDriverWait(driver, 10)
first_result = wait.until(EC.presence_of_element_located((By.XPATH, '//div[@class="sc-f70bb44c-0 sc-c6619d27-2 iYXUgb"]')))  

first_result.click()

driver.quit()

search box html kodu incele yaparak elde ettim:

<input maxlength="200" spellcheck="false" class="sc-8829bc3d-3 ikgYUd desktop-input" type="text" placeholder="Search coin, pair, contract address, exchange, or post" value="" xpath="1">

Aldığım Hata:

search_box = browser.find_element(By.XPATH, "(//input[@placeholder='Search coin, pair, contract address, exchange, or post'])[1]")
  File "C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 742, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 348, in execute
    self.error_handler.check_response(response)
  File "C:\Users\furka\Desktop\GokhanAbiDenemeler\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(//input[@placeholder='Search coin, pair, contract address, exchange, or post'])[1]"}
  (Session info: chrome=120.0.6099.130); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
	GetHandleVerifier [0x00007FF62B842142+3514994]
	(No symbol) [0x00007FF62B460CE2]
	(No symbol) [0x00007FF62B3076AA]
	(No symbol) [0x00007FF62B351860]
	(No symbol) [0x00007FF62B35197C]
	(No symbol) [0x00007FF62B394EE7]
	(No symbol) [0x00007FF62B37602F]
	(No symbol) [0x00007FF62B3928F6]
	(No symbol) [0x00007FF62B375D93]
	(No symbol) [0x00007FF62B344BDC]
	(No symbol) [0x00007FF62B345C64]
	GetHandleVerifier [0x00007FF62B86E16B+3695259]
	GetHandleVerifier [0x00007FF62B8C6737+4057191]
	GetHandleVerifier [0x00007FF62B8BE4E3+4023827]
	GetHandleVerifier [0x00007FF62B5904F9+689705]
	(No symbol) [0x00007FF62B46C048]
	(No symbol) [0x00007FF62B468044]
	(No symbol) [0x00007FF62B4681C9]
	(No symbol) [0x00007FF62B4588C4]
	BaseThreadInitThunk [0x00007FF9A7AD257D+29]
	RtlUserThreadStart [0x00007FF9A988AA58+40]

Selenium’a ihtiyaç yok gibi duruyor. Hemen eski bir konumun reklamını yapayım.

Tavsiyeniz için çok teşekkür ederim, ilgili yazınızı okudum çok güzel bilgiler içeriyor fakat selenium ile yapabilmek istiyorum

:+1:

Search’e tiklayana kadar yaratilmiyor gibi input box ve etrafindaki elemanlar…