无法获取正确的WebElement标识符(在iCloud.com上登录)

问题描述 投票:0回答:2

我无法识别“使用Apple ID登录”元素(在iclod.com页面)。

这是我现在正在使用的:WebElement用户名= driver.findElement(By.xpath(“ // [@ id = \” account_name_text_field \“]”));username.sendKeys(“ [email protected]”);

[此外,我尝试使用Chropath和Ranorex创建的CSS,但仍无法正常工作。我做错了吗?

Path to needed Element

java selenium automation icloud
2个回答
0
投票

请检查以下解决方案。 iframe与您的网页相关联,与Web元素输入框进行交互之前,您需要切换到iframe。

driver = webdriver.Chrome(executable_path=r" path of chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("https://www.icloud.com")
wait.until(EC.presence_of_element_located((By.ID, "auth-frame")))
driver.switch_to.frame("auth-frame")
inputBox = wait.until(EC.element_to_be_clickable((By.ID, "account_name_text_field")))
inputBox.send_keys("your test")

# switch back to main window
driver.switch_to.default_content()

输出:

enter image description here


0
投票

该元素在iframe内部,您需要首先进行切换。

您可以使用.frameToBeAvailableAndSwitchToIt

driver.get("https://www.icloud.com/");
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("auth-frame")));
WebElement username = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("account_name_text_field")));
username.sendKeys("[email protected]");

添加WebDriverWait,网络加载时间很长。

© www.soinside.com 2019 - 2024. All rights reserved.