Home > Software engineering >  Button not clicking in selinium
Button not clicking in selinium

Time:10-05

I have tried xpath and CSS selector in build search buy id and class as well queries but am unable to click the Expand all button.

Button

Link to the website: https://etherscan.io/token/0x2b591e99afe9f32eaa6214f7b7629768c40eeb39#readContract

<div class="d-flex justify-content-between mb-3">
<p class="ml-1 mr-3 mb-1">
<i class="far fa-file-alt text-secondary mr-1"></i> Read Contract Information</p>
<span>
<a href="#" class="mr-1 expandCollapseAllButton" onclick="expandCollapseAll()">[Expand all]</a> 

Locators used: find_element_by_id

find_element_by_xpath

find_element_by_partial_link_text

find_element_by_tag_name

find_element_by_class_name

CodePudding user response:

The Expand all button is in an Iframe. Need to Switch to iframe to perform click operation. And better to apply some waits:

# Imports Required:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver.get("https://etherscan.io/token/0x2b591e99afe9f32eaa6214f7b7629768c40eeb39#readContract")

wait = WebDriverWait(driver,30)

frame = wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"readcontractiframe")))

expandall = wait.until(EC.element_to_be_clickable((By.XPATH,"//a[@onclick='expandCollapseAll()']")))
expandall.click()
  • Related