0

I'm trying to automate downloading a report, but my script is refusing to find the element to click on...

def wait_click(browser, by_what, where):
    wait = WebDriverWait(browser, 20)
    wait.until(EC.element_to_be_clickable((by_what, where))).click()

tillf_export = '//*[@id="panel__6940363340341543984_linkb_6940363340341543984"]'

# inside class
def download_tillf(self):
    self.browser.get(system_export)
    wait_click(self.browser, By.XPATH, tillf_export)

I've tried every possible way, switching away from XPATH, using parent elements and even execute_script with the js.

This is the div:

<table class="dxrpControl" cellspacing="0" cellpadding="0" id="panel__6940363340341543984" border="0" style="border-collapse:collapse;border-collapse:separate;">
        <tbody><tr>
            <td id="panel__6940363340341543984_HC" class="dxrpHeader dxrp-headerClickable dx-borderBox" style="text-align: center; border-bottom: 1.33333px solid rgb(198, 198, 198); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px;"><div id="panel__6940363340341543984_CB" class="dxrpCollapseButton" style="margin-top: 1px;">
                <img id="panel__6940363340341543984_CBImg" class="dxWeb_rpCollapseButton" src="/test/jlltp02/sjalvservicerdr/DXR.axd?r=1_89-UNelo" alt="Collapse/Expand">
            </div><div class="dxrpHCW" style="padding-right: 19px;">
                ** <span id="panel__6940363340341543984_RPHT" class="dxrpHT dx-vam">Tillfällig export</span> 
            </div></td>
        </tr><tr class="dxrpCR">
            <td id="panel__6940363340341543984_RPC" class="dxrp dxrpcontent dx-borderBox"><div class="dxrpAW" style="">
                <div id="panel__6940363340341543984_CRC" class="dx-borderBox dxrpCW">
                    <table border="0">
                        <tbody><tr>
                            <td><span class="UTDATANODTITLEDESC">Tillfällig export kan användas för att snabbt ta ned svaret på en fråga genom att bara ändra den i "Automatiska frågor". Detta för att slippa gå in i Citrix och spara ned filen på M:.</span></td>
                        </tr><tr>
                            <td valign="top"><a id="panel__6940363340341543984_linkb_6940363340341543984" class="UTDATANODLINK" href="javascript:outputClick('6940363340341543984');">&gt;&gt; Tillfällig export</a></td>
                        </tr>
                    </tbody></table>
                </div>
            </div></td>
        </tr>
    </tbody></table>

Can anyone see what I'm doing wrong? Would be forever grateful!

QPT
  • 1

1 Answers1

0

The id attribute of the desired element looks dynamic and the element itself is possibly a dynamic element so to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using PARTIAL_LINK_TEXT:

    Tillfällig export
    
  • Using CSS_SELECTOR:

    a.UTDATANODLINK[id*='linkb']
    
  • Using XPATH:

    //a[@class='UTDATANODLINK' and contains(., 'Tillfällig export')]
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for the suggestion, unfortunatly it's not working and I still get the timed out-error.. Is there a possibility it's a non-clickable element or something? – QPT Jun 18 '22 at 07:49
  • So it should work if I'm at that page and execute with: WebDriverWait(browser, 20).until(EC.element_to_be_clickable ((By.XPATH, "//a[@class='UTDATANODLINK' and contains(., 'Tillfällig export')]"))).click() – QPT Jun 18 '22 at 11:05
  • How about your test results? – undetected Selenium Jun 18 '22 at 12:17
  • It won't work.. I can't even store any of the elements regarding that link, not in the script or if I run it through the terminal. The file is created from an SQL-query when the link is clicked, can that be a problem? If I type this in the browser console, the "click" is executed: javascript:outputClick('6940363340341543984'); Is there any way to emulate that in the python script? – QPT Jun 19 '22 at 00:46
  • OK, I've taken some steps forward to the solution. When I just enter the page, the link is not clickable or even recognizable by JS or Selenium. When i right click the link to inspect it, it becomes active. How can I do this in Selenium? – QPT Jun 27 '22 at 11:30