-1

Access to a hosted MariaDB using a connector is not allowed by the provider. I therefore try to export some tables using a Python script with Selenium. I do not manage to find / click the export button of phpMyAdmin.

I try to locate the button using its XPATH, obtained with the Chrome browser. I updated Chrome, the driver, Selenium to the latest versions. Attempted to make the driver wait:

(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='navigationbar']/ul[@id='topmenu']//li//img[@title='Exporteren']"))).click())

The problem is that for some reason, the button cannot be found by the driver. I tried to search by xpath, class, css, … without success. I do not find any frame in the html code. Below some html code (that seems to get interpreted in the question...)

HTML:

    <div class="navigationbar"><ul id="topmenu"  class="resizable-menu">
    <li>
            <a href="server_status.php" class="tab">
            <img src="themes/dot.gif" title="Status" alt="Status" class="icon ic_s_status" />&nbsp;Status
            </a>
        </li>
    <li>
            <a href="server_export.php" class="tab">
            <img src="themes/dot.gif" title="Exporteren" alt="Exporteren" class="icon ic_b_export" />&nbsp;Exporteren
            </a>
        </li>
    <li>

Code trials:

python
    btnexp = driver.find_element_by_xpath("//*[@id='topmenu']/li[4]/a/img")
    btnexp.click()

Error message:

no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='topmenu']/li[4]/a/img"}
RobertDL
  • 23
  • 1
  • 7

3 Answers3

1

Activation of the most recent window: driver.switch_to_window(driver.window_handles[-1])

RobertDL
  • 23
  • 1
  • 7
0

To click() on the element with text as Exporteren you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried the XPATH variant and got a TimeoutException – RobertDL Sep 11 '19 at 12:21
  • Idem with the css selector – RobertDL Sep 11 '19 at 12:23
  • For some reason, the element with the text 'Exporteren' does not seem to be found. – RobertDL Sep 11 '19 at 12:29
  • @RobertDL Checkout the reference discussion I have added to the answer on **no such element: Unable to locate element** – undetected Selenium Sep 11 '19 at 12:30
  • I updated both Selenium and the driver to the latest versions. I'm afraid it does not make any difference. – RobertDL Sep 11 '19 at 13:19
  • Installed latest versions of Selenium and driver. No effect. – RobertDL Sep 11 '19 at 13:34
  • Is it possible that the element cannot be detected by the driver? This would occur if there was a frame. Are there any other possibilities? – RobertDL Sep 11 '19 at 13:52
  • In the html code, I see no reference to a frame or iframe. – RobertDL Sep 11 '19 at 13:53
  • @RobertDL The reference discussions have all the possibilities listed along with their respective solutions. Check out the reference discussion points one by one and dig out the main issue and update the question accordingly. We can solve it in no time. – undetected Selenium Sep 11 '19 at 13:54
  • I tried to include some more html code in the question, but it gets interpreted and does not show in the question. I added ''' to mark the code as such and a ~. Neither helps. I tried the suggested steps, but without result. – RobertDL Sep 11 '19 at 15:16
  • I tried to find other elements on this web page. And I'm experiencing problems for finding them. It seems the problem is not limited to just the button – RobertDL Sep 11 '19 at 15:31
  • In the script, I opened a new window. Apparently, the find_element instructions were oriented towards the first window and not to the last. Solution: driver.switch_to_window(handle). The last handle used is found through driver.window_handles[-1]. XPATH now seems to find some info. I go on testing. – RobertDL Sep 12 '19 at 19:44
  • @RobertDL Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers. – undetected Selenium Sep 13 '19 at 08:43
-1

Have you tried locating the element by Class Name?

content = driver.find_element_by_class_name('icon ic_s_status')
content = driver.find_element_by_class_name('icon ic_b_export')
JeffreyB
  • 1
  • 1
  • Yes, but to no avail: – RobertDL Sep 11 '19 at 11:39
  • I get a NoSuchElementException – RobertDL Sep 11 '19 at 11:39
  • Is it possible that the element is included in a container of some kind, so that I have to address a higher level element first? It is common when using frames, but maybe there are other constructs with a similar operation. – RobertDL Sep 11 '19 at 15:26
  • Neither of these will work because `find_element_by_class_name()` expects a single class name and you have passed in two class names (space between them). This will throw an error. You can change these into a CSS selector like `.icon.ic_s_status` and it should work. – JeffC Sep 12 '19 at 21:44