Home > Mobile >  Element not found when finding table selenium
Element not found when finding table selenium

Time:10-06

I am trying to read the table and get the values for the columns of address and value. The can't find element error is returned. The page: https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances

Code

My code:

driver=webdriver.Firefox()

ga=pandas.read_csv("contracts/adresses.csv")
for i in range (ga.size-1):
        fj=ga.iloc[i][0]
        # driver.get("https://etherscan.io/address/" str(fj))

driver.get("https://etherscan.io/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52#balances")
wait = WebDriverWait(driver,10)

frame = 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 = simpleTable.find_elementsBy.TAG_NAME("tr")

    
for i in range(1,len(rows)):
        cols = i.find_elements(By.TAG_NAME("td"))
        for g in cols:
            g.getText()

HTML code:

<thead class="thead-light">
<tr>
<th scope="col" width="1">Rank</th>
<th scope="col">Address</th>
<th scope="col">Quantity
</th>
<th scope="col">Percentage</th>
<th id="col_value_Title" scope="col">Value</th>
<th id="col_analytics_Title" scope="col">Analytics</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 7
(0xbe0eb53f46cd790cd13851d5eff43d12404d33e8)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xbe0eb53f46cd790cd13851d5eff43d12404d33e8" target="_parent">Binance 7</a></span></td><td>8,623,839.536582375549486936</td><td>52.0150% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:100.0000%;" aria-valuenow="52.0150" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$3,659,513,869.72</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xbe0eb53f46cd790cd13851d5eff43d12404d33e8#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>2</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 8
(0xf977814e90da44bfa03b6295a0616a897441acec)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xf977814e90da44bfa03b6295a0616a897441acec" target="_parent">Binance 8</a></span></td><td>4,500,000</td><td>27.1419% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:52.1809%;" aria-valuenow="27.1419" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$1,909,568,509.93</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xf977814e90da44bfa03b6295a0616a897441acec#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>3</td><td><span data-toggle="tooltip" title="" data-original-title="Public Tag: Binance 9
(0x001866ae5b3de6caa5a51543fd9fb64f524f5478)"><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x001866ae5b3de6caa5a51543fd9fb64f524f5478" target="_parent">Binance 9</a></span></td><td>588,959.49910460999996837</td><td>3.5523% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:6.8294%;" aria-valuenow="3.5523" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$249,924,114.03</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0x001866ae5b3de6caa5a51543fd9fb64f524f5478#tokenAnalytics" target="_parent"><i class="ml-2 fas fa-chart-line fa-lg"></i></a></td></tr><tr><td>4</td><td><span><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xb4b3351918a9bedc7d386c6a685c42e69920b34d" target="_parent">0xb4b3351918a9bedc7d386c6a685c42e69920b34d</a></span></td><td>211,336.9</td><td>1.2747% <div class="progress mt-1" style="height:2px;"><div class="progress-bar bg-primary" role="progressbar" style="width:2.4506%;" aria-valuenow="1.2747" aria-valuemin="0" aria-valuemax="100"></div></div></td><td>$89,680,508.72</td><td><a href="/token/0xB8c77482e45F1F44dE1745F52C74426C631bDD52?a=0xb4b3351918a9bedc7d386c6a685c42e69920b34d#

CodePudding user response:

!pip install selenium (jupyter notebook)

or

pip install selenium ( command prompt)

Install and try it again !

CodePudding user response:

There is a lot of syntax error in the code:

rows = simpleTable.find_elementsBy.TAG_NAME("tr")

should be

rows = simpleTable.find_elements(By.TAG_NAME,"tr")

And this

cols = i.find_elements(By.TAG_NAME("td"))

should be

cols = rows[i].find_elements(By.TAG_NAME,"td")

And to get Text from a WebElement in python use .text or .get_attribute("innerText") It should be something like this:

print(g.text)

Try with this code:

simpleTable = driver.find_element(By.XPATH, "//div[@id='maintable']//table")

rows = simpleTable.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)
  • Related