サービス
サービスを探す
プロ人材を探す
仕事を探す
ブログを探す
elem = driver.find_element(ロケータ, "対象")
elem_list = driver.find_elements(ロケータ, "対象")
見つからなかったら [] を返す
from selenium.webdriver.common.by import By
By.XPATH
from selenium.webdriver.common.by import By
By.CSS_SELECTOR
from selenium.webdriver.common.by import By
By.ID
from selenium.webdriver.common.by import By
By.CLASS_NAME
from selenium.webdriver.common.by import By
By.NAME
<form>内の<input>に対して使う
from selenium.webdriver.common.by import By
By.TAG_NAME
from selenium.webdriver.common.by import By
By.PARTIAL_LINK_TEXT
from selenium.webdriver.common.by import By
By.LINK_TEXT
elem.text
elem.tag_name
elem.get_attribute("属性")
elem.get_attribute("outerHTML")
elem.size["width"]
elem.size["height"]
elem.location["x"]
elem.location["y"]
exists = bool(driver.find_elements(セレクタ, "対象"))
if exists:
elem.is_displayed()
elem.is_enabled()
from selenium.common.exceptions import NoSuchElementException
try:
elem = driver.find_element(セレクタ, "対象")
except NoSuchElementException as e:
print(e)