gpt4 book ai didi

java - 获取NoSuchElementException : no such element: Unable to locate element

转载 作者:行者123 更新时间:2023-12-02 08:41:22 24 4
gpt4 key购买 nike

我正在尝试将其自动化。但是,当我尝试将文本发送到文本字段时,它收到 NoSuchElementException。我也尝试过webdriverwait。但没有运气。窗口顶部有一个弹出窗口。我关闭了它,还尝试添加 --disable-popup-blocking 参数。但它仍然不起作用。所以有人可以告诉我我在这里做错了什么吗?我对此表示高度赞赏。谢谢。

    System.setProperty("webdriver.chrome.driver", "chromedriver/chromedriver.exe");

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
options.addArguments("chrome.switches", "--disable-extensions");

WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get(URL);

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.scrollBy(0,250)");

driver.findElement(By.cssSelector("#txt_insert2055107")).click();
driver.findElement(By.cssSelector("#txt_insert2055107")).sendKeys("Test");
driver.findElement(By.id("txt_insert2055108")).click();
driver.findElement(By.id("txt_insert2055108")).sendKeys("Test");
driver.findElement(By.id("btnsubmit")).click();

driver.close();

最佳答案

您无法在输入中发送文本,因为您需要先切换到 iframe。请找到以下工作代码:

https://www.frontrush.com/FR_Web_App/Player/PlayerSubmit.aspx?sid=MTA1NTc=-9M6ha/5BuDo=&ptype=recruit

代码:

        driver.get("https://columbiacougars.com/sb_output.aspx?frform=8&path=mbball");
driver.switchTo().frame(0);

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

WebDriverWait wait = new WebDriverWait(driver, 10);

Actions action = new Actions(driver);
WebElement firstName=wait.until(ExpectedConditions.elementToBeClickable(By.id("txt_insert2055107")));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", firstName);
action.moveToElement(firstName).sendKeys("Test").perform();
WebElement lastName=wait.until(ExpectedConditions.elementToBeClickable(By.id("txt_insert2055108")));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", lastName);
lastName.sendKeys("Test");
action.moveToElement(lastName).sendKeys("Test").perform();
WebElement clickElement=wait.until(ExpectedConditions.elementToBeClickable(By.name("btnsubmit")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", clickElement);
driver.close();

enter image description here

关于java - 获取NoSuchElementException : no such element: Unable to locate element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61375275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com