I am trying to get some data from a website but getting below error. It worked last night but when I rerun in today it is suddenly not able to locate the elements. Today, I tried almost I could but Couldn't resolve it.
Tools and Language - Python, Selenium, Chrome, Chromedriver, AWS Cloud 9, EC2
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('https://www.espncricinfo.com/series/19496/scorecard/1198235/england-vs-australia-1st-t20i-england-v-australia-2020')
time.sleep(20)
element_text = driver.find_element_by_xpath('//*[@id="main-container"]/div/div[2]/div[2]/div/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]').text
print(element_text)
Error message
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="main-container"]/div/div[2]/div[2]/div/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]"}
I tried below thing
- Added and removed sleep time. Increased and decreased sleep time
- Used full Xpath, Xpath, find by class
- Tried to locate different elements.
- Different pages of this.
Referred to various site still couldn't resolve. I am new to python.