-1

I wrote this:

from selenium import webdriver  
driver = webdriver.Chrome(executable\_path=**"C:\\\\browserdrivers\\\\chromedriver.exe")  
driver.get("https://www.aliexpress.com/item/1005004580390613.html?spm=a2g0o.search0304.0.0.2b6c66b9cAGH2z&algo\_pvid=f3d04756-9c4f-4971-a2e2-c7d03e07305f&aem\_p4p\_detail=202207310340491186137100550600065998606&algo\_exp\_id=f3d04756-9c4f-4971-a2e2-c7d03e07305f-2&pdp\_ext\_f=%7B%22sku\_id%22%3A%2212000029704251181%22%7D&pdp\_npi=2%40dis%21USD%21%213.29%21%21%21%21%21%402100bdec16592640492515275ecd10%2112000029704251181%21sea")  

w = driver.find\_element\_by\_xpath('//\*\[@id="root"\]/div/div\[2\]/div/div\[2\]/div\[4\]/div\[1\]/span')  
print("w")

and this is what it wrote:

"C:\\Program Files\\Python310\\python.exe" "C:/לימוד סלניום/ראשי.py"

C:\\לימוד סלניום\\[ראשי.py:2](https://ראשי.py:2): DeprecationWarning: executable\_path has been deprecated, please pass in a Service object

  driver = [webdriver.Chrome](https://webdriver.Chrome)(executable\_path="C:\\\\browserdrivers\\\\chromedriver.exe")

Traceback (most recent call last):

  File "C:\\לימוד סלניום\\[ראשי.py](https://ראשי.py)", line 5, in <module>

w = driver.find\_element\_by\_xpath('//\*\[@id="root"\]/div/div\[2\]/div/div\[2\]/div\[4\]/div\[1\]/span')

AttributeError: 'WebDriver' object has no attribute 'find\_element\_by\_xpath'

Process finished with exit code 1
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

1

Your problem is that you are using deprecated syntax. In newer versions of Selenium, find_element_** was replaced with (for example) find_element(By.ID, (...). In your case, a correct way of locating that element would be as follows (considering your XPATH to be correct):

w = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//\*\[@id="root"\]/div/div\[2\]/div/div\[2\]/div\[4\]/div\[1\]/span'))) 

You also need the following imports:

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

Selenium documentation can be found at: https://www.selenium.dev/documentation/

Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30