I am trying to loop through the pages and print the values for the table but it can't click the next button.
Error:
Selenium.common.exceptions.ElementClickInterceptedException: Message:
Element <a class="page-link"
href="javascript:move('generic-tokenholders2?a=0xB8c77482e45F1F44dE1
745F52C74426C631bDD52&sid=&m=normal&s=16579517055253348798759097&p=2')">
is not clickable at point (1148,2553) because another element <div id="overlay">
obscures it`
Page: https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances
My Code:
driver.get("https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances")
wait = WebDriverWait(driver,30)
# num=driver.find_element(By.CSS_SELECTOR, "/html/body/div[2]/div[3]/div/div/ul/li[3]/span/strong[2]").getText()
for i in range(1,20):
time.sleep(5)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"tokeholdersiframe")))
print("udj")
simpleTable = driver.find_element(By.XPATH,"/html/body/div[2]/div[3]/table")
rows = driver.find_elements(By.TAG_NAME,"tr")
for i in range(1,len(rows)):
cols = rows[i].find_elements(By.TAG_NAME,"td")
for g in cols:
print(g.text)
next = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='d-inline-block']//a[@aria-label='Next']")))
driver.execute_script("arguments[0].scrollIntoView(true);",next)
driver.execute_script("window.scrollBy(0,-200);")
next.click()
driver.switch_to.default_content()
Update: Error pmadhu: `
CodePudding user response:
If you observe in the loop you are switching to a iframe
performing some actions and clicking on Next
.
When the 2nd page opened the scope is still on the previous page iframe
and you are trying to find an iframe
within that. Which is not the correct workflow.
You need to perform switch_to.default_content()
after clicking on Next
and then try to do the same on each page.
Below code did click on the Next
without any exception:
driver.get("https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances")
wait = WebDriverWait(driver,30)
for i in range(5):
time.sleep(5)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"tokeholdersiframe")))
next = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='d-inline-block']//a[@aria-label='Next']")))
driver.execute_script("arguments[0].scrollIntoView(true);",next)
driver.execute_script("window.scrollBy(0,-200);")
next.click()
driver.switch_to.default_content()