I’m trying to get as many easymc.io accounts keys as I can, I tried to get the value of a button but it doesn’t and when I’m trying to find the element_by_xpath it says that the xpath does not exist
JavaScript
x
11
11
1
#from bs4 import BeautifulSoup
2
from selenium import webdriver
3
from selenium.webdriver.chrome.options import Options
4
5
CHROMEDRIVER_PATH = 'C:\Users\Downloadschromedriver_winchromedriver.exe'
6
options = Options()
7
options.headless = False
8
driver = webdriver.Chrome(CHROMEDRIVER_PATH, options=options)
9
driver.get('https://easymc.io/get?new')
10
element = driver.find_element_by_xpath('//*[@id="root"]/div[2]/div[1]/div[2]/div/div[2]/div[2]/div/div[2]/div[2]/div/input')
11
Advertisement
Answer
To scrape the value of the accounts keys e.g. 8yBAnUFoNlj3JJHzFE7t
you need to induce WebDriverWait for the visibility_of_element_located()
and you can use either of the following Locator Strategies:
Using
CSS_SELECTOR
:JavaScript131driver.get('https://easymc.io/get?new')
2print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input.form-control[aria-label='Alt Token']"))).get_attribute("value"))
3
Using
XPATH
:JavaScript131driver.get('https://easymc.io/get?new')
2print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@class='form-control' and @aria-label='Alt Token']"))).get_attribute("value"))
3
Console Output:
JavaScript1218yBAnUFoNlj3JJHzFE7t
2
Note : You have to add the following imports :
JavaScript141from selenium.webdriver.support.ui import WebDriverWait
2from selenium.webdriver.common.by import By
3from selenium.webdriver.support import expected_conditions as EC
4
References
You can find a couple of relevant discussions on NoSuchElementException in: