简体   繁体   中英

find element by id using selenium

Im using firefox on ubuntu 22.04 (Codename: jammy) (I installed it with apt and not snap). My Selenium Version is (4.2.0) and I'm using python3.

My code:

#!/bin/usr/python3
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
#driver = webdriver.PhantomJS()
driver.get('https://euw.leagueoflegends.com/en-gb/')
time.sleep(5)
driver.refresh()


#search_field = driver.find_element_by_id('truste-show-consent')
#search_field = driver.find_element("id", "login")
#ID = "id"
#search_field = driver.find_element(By.ID, "login")
search_field = driver.find_element(By.ID,'truste-show-consent')

#driver.find_element("id", "login")

print(search_field.text)
driver.send_keys(Keys.F5)
search_field.click()

I'm getting the following error message:

WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:192:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.jsm:404:5
element.find/</<@chrome://remote/content/marionette/element.js:291:16

To be honest, I accessed this page on my Firefox driver and I could not find any id="truste-show-consent" so maybe that's the problem.

If you need to login with credentials or something first and then the specific id appears, you have to do the same actions with selenium.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM