Issue
I'm trying to log in to https://support.sentinelone.com/
through selenium. Somehow I'm unable to enter my credentials. Here is my code.
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/chromedriver");
ChromeOptions options = new ChromeOptions();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://support.sentinelone.com/hc/en-us/restricted?return_to=https%3A%2F%2Fsupport.sentinelone.com%2Fhc%2Fen-us");
Thread.sleep(5000);
WebDriverWait wait = new WebDriverWait(driver, 60);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("descendant::*[@class='credentials']/descendant::input[1]")))
.sendKeys("[email protected]");
driver.findElement(By.cssSelector("#user_password")).sendKeys("myPassword");
driver.findElement(By.id("sign-in-submit-button")).click();
Thread.sleep(500);
List<WebElement> folders = driver.findElements(By.cssSelector(".blocks-item a"));
System.out.println(folders.size());
driver.findElement(By.cssSelector(".blocks-item:nth-child(1) a")).getAttribute("href");
}
I get the error as
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: descendant::*[@class='credentials']/descendant::input[1] (tried for 60 second(s) with 500 milliseconds interval) Build info: version: '4.1.0', revision: '87802e897b' System info: host: 'rkeerthi-mba', ip: 'fe80:0:0:0:8ff:bcdc:1025:e4b1%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '11.5', java.version: '16.0.2' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 97.0.4692.99, chrome: {chromedriverVersion: 97.0.4692.71 (adefa7837d02a..., userDataDir: /var/folders/6h/hr_vvn9j0sl...}, goog:chromeOptions: {debuggerAddress: localhost:52226}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), se:cdp: ws://localhost:52226/devtoo..., se:cdpVersion: 97.0.4692.99, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true} Session ID: 2f312b7acb65d1e79b013c4f4e05a6db at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:138) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231) at SentinalOneCrawler.main(SentinalOneCrawler.java:24)
Not sure of where I'm going wrong. Please let me know how can I fix this.
Solution
Your locators are correct, but the Creds input boxes are in an iframe.
So first switch to an iframe with the below XPath:
//iframe[@frameborder]
and then you would be able to access the element.
new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@frameborder]")));
and once you are switched to the frame, then use this line:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("descendant::*[@class='credentials']/descendant::input[1]")))
.sendKeys("[email protected]");
also, once you are done with iframe you should switch back to the defaultContent
driver.switchTo().defaultContent();
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.