python - selenium find_element_by_xpath returns NoSuchElementException -
i'm working selenium im having problems find_element_by_xpath
method. having tag https://citizenportal.rld.state.nm.us/default.aspx website:
<a title="permits" href="javascript:void(0);" module="permits">permits</a>
im trying create click event click on permits tag doing:
from selenium import webdriver selenium.webdriver.common.keys import keys selenium.webdriver.common.by import driver = webdriver.chrome() driver.get('https://citizenportal.rld.state.nm.us/default.aspx') driver.find_element_by_xpath('//a[@title="permits"]').click()
however im getting error , cant figure out
--------------------------------------------------------------------------- nosuchelementexception traceback (most recent call last) <ipython-input-25-ecbedf623e4f> in <module>() 6 driver.get('https://citizenportal.rld.state.nm.us/default.aspx') 7 ----> 8 driver.find_element_by_xpath('//a[@title="permits"]').click() 9 c:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in find_element_by_xpath(self, xpath) 304 driver.find_element_by_xpath('//div/td[1]') 305 """ --> 306 return self.find_element(by=by.xpath, value=xpath) 307 308 def find_elements_by_xpath(self, xpath): c:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in find_element(self, by, value) 782 return self.execute(command.find_element, { 783 'using': by, --> 784 'value': value})['value'] 785 786 def find_elements(self, by=by.id, value=none): c:\anaconda\lib\site-packages\selenium\webdriver\remote\webdriver.pyc in execute(self, driver_command, params) 247 response = self.command_executor.execute(driver_command, params) 248 if response: --> 249 self.error_handler.check_response(response) 250 response['value'] = self._unwrap_value( 251 response.get('value', none)) c:\anaconda\lib\site-packages\selenium\webdriver\remote\errorhandler.pyc in check_response(self, response) 191 elif exception_class == unexpectedalertpresentexception , 'alert' in value: 192 raise exception_class(message, screen, stacktrace, value['alert'].get('text')) --> 193 raise exception_class(message, screen, stacktrace) 194 195 def _value_or_default(self, obj, key, default): nosuchelementexception: message: no such element: unable locate element: {"method":"xpath","selector":"//a[@title="permits"]"} (session info: chrome=57.0.2987.133) (driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=windows nt 6.3.9600 x86_64)
i've tried different combinations keeps returning error. doing wrong?
edit includes hole span , elements.
<span style="display:inline-block;" id="span_tab_1"> <table role="presentation" tag="navbar" border="0" cellspacing="0" cellpadding="0" class="tab_bar_table aca_nowrap"> <tbody> <tr> <td class="aca_itemleft aca_leftoff"></td> <div> <a title="permits" href="javascript:void(0);" module="permits">permits</a> </div> <td class="aca_itemcenter aca_itemcenter_fontsize aca_centeroff"> </td> <td class="aca_itemright aca_rightoff"></td> </tr> < /tbody> </table> </span>
your xpath fine. prefer use css selectors, e.g. "a[title='permit']"
, since faster , better supported.
the problem element want inside iframe.
<iframe id="acaframe" name="acaframe" ... src="/welcome.aspx">
you need switch frame , find work.
see this page more details.
Comments
Post a Comment