I have Python-3.4.1 32 bit on a Windows 7 64 bit machine with Selenium using Google Chrome version 39. I am endeavoring to automatically download a CSV file from a secured website after logging in. In Chrome, while opening this website, it gives an icon saying Load unsafe script which we have to manually click to load the different elements on the website. I have to click on a Menu button which opens a drop down list from which I have to click a button. The code for the portion of page is:
<!DOCTYPE html>
<html id="ext-gen3" class=" ext-strict x-viewport" decorator="blank">
<head></head>
<body id="ext-gen4" class="ext-gecko3 ext-linux cwc-view x-border-layout-ct" onload="cwc.getFrameworkWindow()">
<div id="cwc_header" class=" masthead x-border-panel" style="left: 0px; top: 0px; width: 1366px; height: 27px;"></div>
<div id="cwcNavPanel" class=" x-panel cwc-navPanel x-border-panel" style="width: 220px; left: 0px; top: 56px;"></div>
<div id="cwcCenterPanel" class=" x-tab-panel cwc-centerPanel x-border-panel" style="left: 228px; top: 35px; width: 1138px;">
<a id="mainContent"></a>
<div id="ext-gen55" class="x-tab-panel-header x-unselectable x-tab-panel-header-plain" style="width: 1138px;"></div>
<div id="ext-gen56" class="x-tab-panel-bwrap">
<div id="ext-gen57" class="x-tab-panel-body x-tab-panel-body-top" style="width: 1138px; height: 331px;">
<div id="ext-comp-943917" class=" x-panel x-panel-noborder x-hide-nosize" style="width: 1136px;"></div>
<div id="ext-comp-943936" class=" x-panel x-panel-noborder" style="width: 1136px;">
<div id="ext-gen365" class="x-panel-bwrap">
<div id="ext-gen366" class="x-panel-body x-panel-body-noheader x-panel-body-noborder" style="width: 1136px; height: 330px;">
<div id="mif-comp-943937" class=" x-panel x-panel-noborder" style="width: 1136px;">
<div id="ext-gen368" class="x-panel-bwrap">
<div id="ext-gen369" class="x-panel-tbar x-panel-tbar-noheader x-panel-tbar-noborder" style="width: 1136px;">
<div id="ext-comp-943935" class="x-toolbar x-small-editor x-toolbar-layout-ct" style="width: 1136px;">
<table class="x-toolbar-ct" cellspacing="0">
<tbody>
<tr>
<td class="x-toolbar-left" align="left">
<table cellspacing="0">
<tbody>
<tr class="x-toolbar-left-row">
<td id="ext-gen422" class="x-toolbar-cell"></td>
<td id="ext-gen424" class="x-toolbar-cell"></td>
<td id="ext-gen426" class="x-toolbar-cell"></td>
<td id="ext-gen428" class="x-toolbar-cell"></td>
<td id="ext-gen430" class="x-toolbar-cell"></td>
<td id="ext-gen432" class="x-toolbar-cell"></td>
<td id="ext-gen434" class="x-toolbar-cell">
<table id="ext-comp-943967" class="x-btn ltr x-btn-noicon x-btn-menu-active" cellspacing="0" style="width: auto;">
<tbody class="x-btn-small x-btn-icon-small-left">
<tr></tr>
<tr>
<td class="x-btn-ml"></td>
<td class="x-btn-mc ">
<em id="ext-gen436" class="x-btn-arrow" unselectable="on" role="menu" aria-haspopup="true">
<button id="ext-gen435" class=" x-btn-text" type="button">
More
</button>
</em>
</td>
<td class="x-btn-mr"></td>
</tr>
<tr></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
<td class="x-toolbar-right" align="right"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="ext-gen370" class="x-panel-body ux-mif-mask-target x-panel-body-noheader x-panel-body-noborder" style="width: 1136px; height: 303px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--
Telephony Applet
-->
<iframe id="ext-gen358" class="ext-shim" frameborder="0" src="/sm/js/9.33.4005/extjs/resources/images/default/s.gif" style="display: block; visibility: visible; z-index: 14998; left: 617px; top: 84px; width: 170px; height: 246px;"></iframe>
<div id="ext-comp-943902" class="x-tip" style="position: absolute; z-index: 20002; visibility: hidden; width: 76px; left: 666px; top: 86px; display: none;"></div>
<div id="cwcNavPanel-xsplit" class="x-layout-split x-layout-split-west x-unselectable x-splitbar-h" style="left: 220px; top: 56px; height: 332px;"></div>
<div id="ext-gen54" class=" x-unselectable x-splitbar-proxy x-splitbar-proxy-h"></div>
<div id="ext-gen359" style="position: absolute; left: -1000px; top: -1000px; visibility:…; text-transform: none; letter-spacing: normal; width: auto;"></div>
<div id="ext-gen76" class="x-shadow" style="z-index: 14999; left: 617px; top: 84px; width: 170px; height: 246px; display: block;"></div>
<div id="ext-comp-943968" class="x-menu x-menu-floating x-layer" style="position: absolute; z-index: 15000; visibility: visible; left: 621px; top: 81px;" role="application">
<a id="ext-gen445" class="x-menu-focus" tabindex="-1" onclick="return false;" href="#" role="presentation" aria-labelledby="ext-comp-943968"></a>
<ul id="ext-gen446" class="x-menu-list" style="height: 244px;" role="menu">
<li id="x-menu-el-ext-comp-943969" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943970" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943971" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943972" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943973" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943974" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943975" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943976" class="x-menu-list-item" role="presentation"></li>
<li id="x-menu-el-ext-comp-943977" class="x-menu-list-item x-menu-item-active" role="presentation">
<a id="ext-comp-943977" class="x-menu-item x-unselectable" href="#" unselectable="on" hidefocus="true" role="menuitem" tabindex="-1">
<img id="ext-gen464" class="x-menu-item-icon " src="/sm/js/9.33.4005/extjs/resources/images/default/s.gif" alt=""></img>
<span id="ext-gen465" class="x-menu-item-text">
Export to Excel
</span>
</a>
I need to manipulate More (button id="ext-gen435" in the code above) and Export to Excel (span id="ext-gen465" in the code above) elements and to manipulate More button I tried:
d_menu = driver.find_element_by_id("ext-gen389")
But the id ("ext-gen389") keeps changing so I tried:
d_menu = driver.find_element(By.XPATH, '//button[text()="Menu"]')
ActionChains(driver).move_to_element(d_menu).click(d_menu).perform()
But that is giving me the error:
Traceback (most recent call last):
File "C:\Users\arjun_m\Desktop\Head_Bashing\Running_Chrome_HPSM.py", line 72, in <module>
d_menu = driver.find_element(By.XPATH, '//button[text()="Menu"]')
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
(Session info: chrome=39.0.2171.65)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)
How do I deal with those two elements?
I tried:
driver.find_element(By.XPATH, '//button[contains(text(),"Menu")]').click()
and it gave me the error:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
driver.find_element(By.XPATH, '//button[contains(text(),"Menu")]').click()
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element
(Session info: chrome=39.0.2171.65)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)
I tried:
driver.find_element(By.XPATH, '//button[contains(text(),"Menu")]').click()
and it's giving me:
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
driver.find_element(By.XPATH, '//button[contains(text(),"Menu")]').click()
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.evaluate threw exception: TypeError: Cannot read property 'click' of null
(Session info: chrome=39.0.2171.71)
(Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)
What does it mean by TypeError: Cannot read property 'click' of null in the trace shown above?
Thanks
cssSelector?