0

I currently have a selenium python script that is working with PhantomJS, but not Firefox. I get this error:

NoSuchElementException('Unable to locate element: Research Project', None, None)

Specifically, it fails on this line of code:

self.webdriver.find_element_by_link_text("Research Project").click()

I've tried some different wait methods with no luck, such as:

WebDriverWait(self.webdriver, 10000).until(EC.presence_of_element_located((By.LINK_TEXT, "Research Project")))

I've also tried using various Xpaths to test if the link text isn't specific enough, which resulted in an ElementNotInteractableException if no wait was implemented, or the wait timing out if implemented.

If it helps, my PhantomJS webdriver is defined as:

args = [
'--ignore-ssl-errors=true',
'--ssl-protocol=any',
'--web-security=false'
]
driver = webdriver.PhantomJS(service_args=args, executable_path='/usr/bin/phantomjs', service_log_path='/tmp/ghostdriver.log')

And my Firefox webdriver is simply defined as:

driver = webdriver.Firefox(executable_path='/usr/local/Cellar/geckodriver/0.21.0/bin/geckodriver')

I can provide more detail if necessary. Any help would be greatly appreciated.

The HTML for the object I'm trying to reference:

<a href="#" id="dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:close_tree" name="dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:close_tree" onclick="RichFaces.ajax(&quot;dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:close_tree&quot;,event,{&quot;parameters&quot;:{&quot;node_id&quot;:5627697,&quot;ajaxRequest&quot;:&quot;true&quot;} ,&quot;incId&quot;:&quot;1&quot;} );return false;" class="publicationTypeLink ariaHasPopup ariaExpanded" onblur="overviewAddnew(null);unselectedDiv(this);" onfocus="overviewAddnew(this);selectedDiv(this);" onmouseout="overviewAddnew(null);unselectedDiv(this);" onmouseover="overviewAddnew(this);selectedDiv(this);" aria-describedby="dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:hiddenDescriptiontree_closed" aria-haspopup="true" aria-expanded="true"><div id="dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:closeTree" style="padding-left:20px;" class="unselectedDiv"><img src="/converis/javax.faces.resource/images/collapsible_panel_triangle_state_expanded.png.xhtml?ln=intern" alt=""><span style="padding-left:15px;">Research Project </span></div><span id="dynaTempSelView:dynaTempSelForm:tree_selector:newLinksDT:0:hiddenDescriptiontree_closed" style="display: none;">Research Project</span></a>
  • Have you checked with firefox to see if this variable is consistent? Maybe try clicking a different element or similar to see if its the same error – Cacoon Jul 05 '18 at 22:34
  • I'm able to click other elements on the page, as the script runs normally up to this failure, but any elements within the table I'm trying to click seem to behave the same way. – Austin Brodeur Jul 06 '18 at 16:25

1 Answers1

0

The relevant HTML would have been helpful to decide on the Locator Strategy. Still, as per your code trials, moving forward as you are trying to invoke click() method so instead of using presence_of_element_located() you need to use element_to_be_clickable() as follows:

  • LINK_TEXT:

    WebDriverWait(self.webdriver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Research Project"))).click() 
    
  • PARTIAL_LINK_TEXT:

    WebDriverWait(self.webdriver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Research Project"))).click()
    
  • XPATH:

    WebDriverWait(self.webdriver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(.,'Research Project')]"))).click()
    

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the suggestion. I gave it a try, but still no luck. I've included the HTML in an edit if you'd like to take a look. – Austin Brodeur Jul 06 '18 at 16:35