Home > Software design >  How To Fix TypeError: 'FirefoxWebElement' object is not subscriptable In Python Selenium
How To Fix TypeError: 'FirefoxWebElement' object is not subscriptable In Python Selenium

Time:10-02

I'm Creating Whatsapp Script. I Have 8k Contacts I Want To Save Them All In Txt File. I'm ​Creating This Script in Selenium. But I'm Getting Error TypeError: 'FirefoxWebElement' object is not subscriptable

enter image description here

Here Is My Code:

from selenium import webdriver
from selenium.webdriver.common import keys
import time

driver = webdriver.Firefox(executable_path="geckodriver.exe")
driver.get("https://web.whatsapp.com/")
input("Qr Code Done? : ")
driver.implicitly_wait(10)

phnenumbers = driver.find_elements_by_class_name('zoWT4')

for number in phnenumbers:
    print(number[0].text)

Thanks For Your Important Time And Help!

CodePudding user response:

driver.find_elements_by_class_name() returns a list of elements, so you probably want

for number in phnenumbers:
    print(number.text)
  • Related