如何找到元素iTunes连接网站的刮擦(爬行)?

2024-05-31 10:44:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要我的应用程序的CFBundleversion,所以我已经尝试了剪贴iTunesConnect网站,但我不能得到元素

我试过:

from selenium import webdriver

driver = webdriver.Firefox()

driver.get("https://appstoreconnect.apple.com/login")

elem = driver.find_element_by_xpath("//input[@id='account_name_text_field']")

我收到以下错误:

elenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@id='account_name_text_field']

我认为网站的结构不同。。。 我该怎么办


Tags: textnameid应用程序元素fieldinput网站
1条回答
网友
1楼 · 发布于 2024-05-31 10:44:22

你的定位器没问题:

driver.find_element_by_xpath("//input[@id='account_name_text_field']")

它在iframe内,需要先切换,使用frame_to_be_available_and_switch_to_itvisibility_of_element_located,如下所示:

driver.get('https://appstoreconnect.apple.com/login')

WebDriverWait(driver, 30).until(expected_conditions.frame_to_be_available_and_switch_to_it((By.ID, "aid-auth-widget-iFrame")))
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located((By.XPATH, "//input[@id='account_name_text_field']")))
elem = driver.find_element_by_xpath("//input[@id='account_name_text_field']")
elem.send_keys("userName")

以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

相关问题 更多 >