I am trying to automate using selenium and python 3 , below is my code what I have tried :
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="download"]/span'))
)
element.click()
HTML :
<a href="javascript:void(0);"
onclick="if(!alen_Button_checkClick('download',event)){return true;};return
htmlbSL(this,2,'download:downloadBtn')"
onkeypress="if(!alen_Button_checkClick('download',event)){return
true;};return htmlbSL(this,2,'download:downloadBtn')" class="urBtnStd1 urV"
id="download" ct="Button" title="Download To Excel" style="white-
space:nowrap;">
<span class="urBtnPadding">
Download To Excel
</span>
</a>
I want to click on "Download To Excel button" but everytime I execute the code whether I search it by xpath or class it doesn't executes and gives timeout error when I increase timeout it doesn't helps or I use Driver.wait
that also doesn't helps.
stacktrace :
EC.element_to_be_clickable((By.XPATH, '//*[@id="download"]/span'))
File "c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message
What am I missing here ?
EDIT 2 :
time.sleep(5)
if driver.find_element_by_id('download'):
print ("Element exists")
time.sleep(5)
if driver.find_element_by_xpath((("//a[@class='urBtnStd1 urV' and @id='download' and @title='Download To Excel']/span[@class='urBtnPadding']"))):
print ("Element exists1")
Stacktrace of edit 2 :
Element exists
Traceback (most recent call last):
File "C:\Users\c5242046\Desktop\test2\backupautomation\bkpalertv1\bkpv1.py", line 73, in <module>
if driver.find_element_by_xpath((("//a[@class='urBtnStd1 urV' and @id='download' and @title='Download To Excel']/span[@class='urBtnPadding']"))):
File "c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 385, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
'value': value})['value']
File "c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with xpath == //a[@class='urBtnStd1 urV' and @id='download' and @title='Download To Excel']/span[@class='urBtnPadding']