Skip to content Skip to sidebar Skip to footer

How To Click On A Element Using Selenium And Python

Provided an xpath below:

Solution 1:

<svg:image>

The <svg:image> element includes images inside SVG documents. It can display raster image files or other SVG files. The only image formats SVG software must support are JPEG, PNG, and other SVG files. Animated GIF behavior is undefined.

SVG files displayed with <image> are treated as an image where external resources aren't loaded, :visited styles aren't applied and they cannot be interactive. To include dynamic SVG elements, try <use> with an external URL. To include SVG files and run scripts inside them, try <object> inside of <foreignObject>.

Note: The HTML spec defines <image> as a synonym for <img> while parsing HTML. This specific element and its behavior only apply inside SVG documents or inline SVG.


xlink:href

The xlink:href attribute defines a link to a resource as a reference <IRI>. The exact meaning of that link depends on the context of each element using it.

Deprecated since SVG 2: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Note: SVG 2 removed the need for the xlink namespace, so instead of xlink:href you should use href.


Solution

To click() on the desired element you need to induce WebDriverWait for the desired element_to_be_clickable and you can use the following solution:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg:image' and starts-with(@class, 'holder') and contains(@xlink:href, 'some')]"))).click()

Note : You have to add the following imports :

from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

Solution 2:

Try the following way to access tag_name.

'//*[local-name()="svg:image"][@class="holder-38"]'

To click on the element use Action Class.

from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.supportimport expected_conditions as ec
from selenium.webdriver.common.action_chainsimportActionChains
elememnt=WebDriverWait(driver, 10).until(ec.presence_of_element_located(("xpath", '//*[local-name()="svg:image"][@class="holder-38"]')))
ActionChains(driver).move_to_element(elememnt).click().perform()

Post a Comment for "How To Click On A Element Using Selenium And Python"