首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法sendKeys到页面

无法sendKeys到页面
EN

Stack Overflow用户
提问于 2022-01-27 06:41:28
回答 1查看 353关注 0票数 2

我正在尝试通过selenium登录到https://support.sentinelone.com/。不知何故我无法输入我的证件。这是我的密码。

代码语言:javascript
复制
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("myUser@user.com");

        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");
    }

我得到的错误是

线程"main“中的

异常:预期条件失败:等待由By.xpath: org.openqa.selenium.TimeoutException构建信息定位的元素的可见性:版本:'4.1.0',修订:'87802e897b‘系统信息:主机:’rkeerthi‘,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‘驱动程序信息: org.openqa.selenium.chrome.ChromeDriver功能{acceptInsecureCerts: false,browserName: chrome,browserVersion: 97.0.4692.99,chrome:{chromedriverVersion: 97.0.4692.71 (adefa7837d02a.,userDataDir: /var/文件夹/6h/hr_vn9j0sl.},goog:色度选项:{debuggerAddress: localhost:52226},javascriptEnabled: true,networkConnectionEnabled: false,pageLoadStrategy: platform: MAC,platformName: MAC,代理:代理(),se:cdp: ws://localhost:52226/devto.se:cdpVersion: 97.0.4692.99,setWindowRect: true,strictFileInteractability: false,超时值:{默示: 0,pageLoad: 300000,脚本: 30000},unhandledPromptBehavior: false and notify,webauthn:extension:credBlob: true,webauthn:extension:largeBlob: true,webauthn:虚拟身份验证者: true}会话ID: 2f312b7acb65d1e79b013c4f4e05a6db在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)

不知道我哪里出了问题。请告诉我怎么解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-27 07:04:26

您的定位器是正确的,但Cred输入框在一个iframe。

因此,首先使用下面的XPath切换到iframe:

代码语言:javascript
复制
//iframe[@frameborder]

然后你就可以访问元素了。

代码语言:javascript
复制
new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@frameborder]")));

一旦您切换到框架,然后使用这一行:

代码语言:javascript
复制
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("descendant::*[@class='credentials']/descendant::input[1]")))
            .sendKeys("myUser@user.com");

而且,一旦您完成了iframe,您应该切换回defaultContent

代码语言:javascript
复制
driver.switchTo().defaultContent();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70874354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档