我不知道无效字符在哪里,它指向代码的末尾.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
def page_is_loaded(driver):
return driver.find_element_by_tag_name("body") != None
driver = webdriver.Chrome()
driver.get("https://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/MyAccount-Register")
year = wait.until(EC.visibility_of_element_located((By.XPATH,'//span[@data-val="1990"]')))
driver.execute_script('arguments[0].scrollIntoView(true);', year)
^
SyntaxError: invalid character in identifier
最佳答案
如前所述,“ 1990”]’中有一个隐藏的符号.当您从StackOverflow复制代码时,有时会发生这种情况.您只需要再次输入此部分.
如果需要向下滚动到目标选项(1990年),请使用
import time
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("https://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/MyAccount-Register")
driver.switch_to_frame(driver.find_element_by_xpath('//iframe[@class="sso-iframe"]'))
wait.until(EC.presence_of_element_located((By.XPATH,'//a[.="YY"]'))).click()
year = wait.until(EC.presence_of_element_located((By.XPATH,'//li[span[@data-val="1990"]]' )))
year.location_once_scrolled_into_view
time.sleep(1)
year.click()