嗨,我正在嘗試自動化
如果我在這里遺漏了什么,請告訴我。
uj5u.com熱心網友回復:
要click()在帶有文本的元素上,Log In / SignUp您可以使用以下任一定位器策略:
xpath:driver.findElement(By.xpath("//div[starts-with(@id, 'defaultAvatar')]//following::span[text()='Log In / SignUp']")).click();
然而,由于該元素是一個動態的元素,所以要click()的元素,你需要引起WebDriverWait的elementToBeClickable(),你可以使用以下的定位策略:
xpath:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[starts-with(@id, 'defaultAvatar')]//following::span[text()='Log In / SignUp']"))).click();
uj5u.com熱心網友回復:
實際上,您的代碼是在頁面正確加載之前單擊登錄按鈕。請添加可見性條件。
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/355903.html
