0

I've been trying to automate a download process, but I am unable to find an element that needs clicking. The element has no ID, and is embedded in a tableau table. I've tried xPath, and it didn't work.

This is the html code of the element I'm trying to click-

image xlink:href="somerandomlink" class="tab-button-zone-image" width="30" height="9"></image

The element also has a outerwidget code, under which the above code for the actual element I want to click can be found-

<div class="tab-zone tab-widget tabSuppressVizTooltipsAndOverlays tabZone-dashboard-object fade-bg" id="tabZoneId26" style="z-index: 35; width: 30px; height: 22px; top: 78px; left: 1315px;">

Code that I've been using is this:

elem1= driver.find_element_by_id('tabZoneId26')
elem1.click()

and

elem= driver.find_element_by_id('//*[@id="tabZoneId26"]/div/div/div/div/div/div/svg/image')
elem.click()

Both didn't work. Can't share link to the page, I'm afraid.

Any help would be greatly appreciated, stuck on this for some time now. Thanks.

2 Answers2

1

You use wrong method find_element_by_id for xpath. Right one is find_element_by_xpath

driver.find_element_by_xpath('//*[@id="tabZoneId26"]/div/div/div/div/div/div/svg/image')

Also your xpath is untrustworthy: try to do better xpath like

driver.find_element_by_xpath('//div[contains(@id,"tabZoneId2")]//svg/image[@class="tab-button-zone-image"]')

Also make sure that web element is in DOM before click it. for example

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By

timeout = 5
wait = WebDriverWait(browser, timeout, poll_frequency=1)
wait.until(
  method=ec.presence_of_element_located((By.XPATH, "YOUR XPATH")))
dropnz
  • 112
  • 2
0
elem1= driver.find_element_by_xpath('//div[@id="tabZoneId26"]//image')
elem1.click()

or

from selenium.webdriver.common.action_chains import ActionChains

elem1 = driver.find_element_by_xpath('//div[@id="tabZoneId26"]//image')
actions = ActionChains(driver)
actions.click(elem1).perform()