2

I am having problems with getting python selenium to find and click on links. I am trying to automate entering student comments into D2L. ICN_Feedback_3400653_125630 the first set of numbers is the grade item ID, and the second set of numbers is the student ID. My plan is to use take comments form gspread and paste them into d2l via selenium. But, i'm not able to click a link that pops up a java script text box.

I have tried different variations of the following:

element = driver.find_elements_by_id('ICN_Feedback_3400653_125630')
element = river.find_element_by_xpath("""//*@id="ICN_Feedback_3400653_125630"]/d2l-icon""")
element = driver.find_element_by_css_selector("#ICN_Feedback_3400653_125630")
element.click()

find_element_by_id() doesn't work because there are 2 instances of the ID on the page, one is the link i need, and the other one is doing something?. Admittedly i am not well versed in this. Am I going about this the wrong way?

Here is the source that I am pulling from:

<div class="dco" id="z_ch" style="display:inline;float:right;"><div 
class="dco_c" style="display:inline;"><a class="d2l-imagelink" 
id="ICN_Feedback_3400653_125630" href="javascript:void(0);" 
onclick="return false;" title="Enter comments for FIRSTNAME LASTNAME in a 
new window" aria-label="Enter comments for FIRSTNAME LASTNAME in a new 
window" 
role="button"><d2l-icon icon="d2l-tier1:edit" class="x-scope d2l-icon- 
0"><svg viewBox="0 0 18 18" preserveAspectRatio="xMidYMid meet"                         
focusable="false" class="style-scope d2l-icon" style="pointer-events: 
none; display: block; width: 100%; height: 100%;"><g class="style-scope 
d2l-icon"><path d="M2.85 10.907l-.672 1.407L.033 17.26a.535.535 0 0 0 0 
.368.917.917 0 0 0 .155.184.917.917 0 0 0 .184.155A.54.54 0 0 0 .56 
18a.48.48 0 0 0 .18-.033l4.946-2.145 1.407-.672 8.53-8.53-4.244- 
4.243zM4.857 14l-1.515.657L4 13.143l.508-1.064 1.415 1.413zM16.707 
5.537l-4.244-4.244.707-.707a2 2 0 0 1 2.83 0L17.414 2a2 2 0 0 1 0 2.83z" 
class="style-scope d2l-icon"></path></g></svg></d2l-icon></a>
</div></div>
JeffC
  • 22,180
  • 5
  • 32
  • 55
Calvin Hobbes
  • 77
  • 1
  • 7
  • @debanjanb Please stop adding [webdriver] and [selenium] tags to all these questions. [webdriver] is referring to the W3C spec and is generic. This, and all the other questions, are referring specifically to Selenium WebDriver which the [selenium-webdriver] tag covers. [selenium] is also too generic and is redundant with [selenium-webdriver]. I'm also removing [xpath] because this isn't a question about XPath... it happens to mention XPath but also mentions CSS selectors and IDs. We don't need to add a tag for every topic mentioned in the question. – JeffC Aug 17 '18 at 21:12
  • @JeffC I feel you have a misunderstanding about tags. Individual volunteers keeps watching specific tags. The questions needs to reach the broader audience for well researched answers. Don't bother too much tag edits instead focus on answering the questions with your well researched answers. – undetected Selenium Aug 18 '18 at 06:46
  • @DebanjanB I understand perfectly well about tags. The tags should be relevant to the question. If you hover each tag, it will describe what the tag covers. You are adding tags that aren't relevant to the questions. I explained in my previous comment. See [tagging](https://stackoverflow.com/help/tagging) for more info. – JeffC Aug 18 '18 at 15:23

1 Answers1

0

As per the HTML you have shared to invoke click() on the desired element you can use the following solution:

driver.find_element_by_xpath("//a[@class='d2l-imagelink'][starts-with(@id,'ICN_Feedback_')][contains(@title,'FIRSTNAME LASTNAME')]").click()

Update

As you are seeing the error Element is not clickable at point following the discussion Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click: try to use the executeScript() method as follows:

myElement = driver.find_element_by_xpath("//a[@class='d2l-imagelink'][starts-with(@id,'ICN_Feedback_')][contains(@title,'FIRSTNAME LASTNAME')]")
driver.execute_script("arguments[0].click();", myElement)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352