0

I wrote a code in Python for Web Scraping and fetching HTML table but its throwing an Attribute Error : 'WebDriver' object has no attribute 'find_elements_by_xpath'

FULL ERROR DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe') Traceback (most recent call last): File "C:\Users\rajat.kapoor\PycharmProjects\RajatProject\FirstPythonFile.py", line 6, in scheme = driver.find_elements_by_xpath('//tbody/tr/td[0]')

Given Below is the Code

from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe')
driver.get('https://www.mutualfundssahihai.com/en/schemeperformance')
driver.maximize_window()
scheme = driver.find_elements_by_xpath('//tbody/tr/td[0]')
benchmark = driver.find_elements_by_xpath('//tbody/tr/td[1]')
result=[]
for i in range(len(riskometer)):
    temporary_data = {'Scheme':scheme.text,
                      'Benchmark':benchmark.text}
    result.append(temporary_data)

df_data = pd.DataFrame(result)
df_data.to_excel('scrapingresult.xlsx',index=False)

I tried writing the code for Web Scraping using Selenium (fetch HTML Table) but its throwing an Attribute Error :'WebDriver' object has no attribute 'find_elements_by_xpath'

FULL ERROR

DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe') Traceback (most recent call last): File "C:\Users\rajat.kapoor\PycharmProjects\RajatProject\FirstPythonFile.py", line 6, in scheme = driver.find_elements_by_xpath('//tbody/tr/td[0]')

Below is the code for the same

from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe')
driver.get('https://www.mutualfundssahihai.com/en/schemeperformance')
driver.maximize_window()
scheme = driver.find_elements_by_xpath('//tbody/tr/td[0]')
benchmark = driver.find_elements_by_xpath('//tbody/tr/td[1]')
result=[]
for i in range(len(riskometer)):
    temporary_data = {'Scheme':scheme.text,
                      'Benchmark':benchmark.text}
    result.append(temporary_data)

df_data = pd.DataFrame(result)
df_data.to_excel('scrapingresult.xlsx',index=False)

1 Answer 1

0

Updated

The same issue can be seen here TypeError: 'module' object is not callable ( when importing selenium ).

The line,

driver = webdriver.chrome('C:\webdrivers\chromedriver.exe')

should be,

driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe')

notice the capital 'C' in Chrome.

Additionally use

driver.find_element("xpath", "#path_selector")

as find_elements_by_xpath is removed.

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

2 Comments

Thanks Abhishek I corrected it but it is still showing the error as : DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = webdriver.Chrome('C:\webdrivers\chromedriver.exe') Traceback (most recent call last): File "C:\Users\rajat.kapoor\PycharmProjects\RajatProject\FirstPythonFile.py", line 6, in <module> scheme = driver.find_elements_by_xpath('//tbody/tr/td[0]') AttributeError: 'WebDriver' object has no attribute 'find_elements_by_xpath'
Try using driver.find_element("xpath", "'//tbody/tr/td[0]'). The function find_elements_by_xpath was deprecated: stackoverflow.com/q/72754651/12071682

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.