gpt4 book ai didi

java - 无法从下拉列表中选择值 : ElementNotVisibleException

转载 作者:行者123 更新时间:2023-12-02 03:40:30 27 4
gpt4 key购买 nike

我正在使用 Java selenium 自动输入用户的数据,但他必须通过下拉列表选择状态。我收到异常错误。

我尝试过使用所有选择器:

drpState.selectByIndex(5);
drpState.selectByValue("CA");
drpState.selectByVisibleText("California");

我有以下 html 代码:

<div class="col-sm-4 form-group">
<label id="xstateLabel">@lang('messages.state')</label>
<select class="form-control js-select" style="width: 100%" id="xstate" name="xstate">
<option value=""> State </option>
<option value="AL" <?php if(isset($usr->state) && $usr->state=='AL'){echo 'selected';} ?>>Alabama</option>
<option value="AK" <?php if(isset($usr->state) && $usr->state=='AK'){echo 'selected';} ?>>Alaska</option>
<option value="AZ" <?php if(isset($usr->state) && $usr->state=='AZ'){echo 'selected';} ?>>Arizona</option>
<option value="AR" <?php if(isset($usr->state) && $usr->state=='AR'){echo 'selected';} ?>>Arkansas</option>
<option value="CA" <?php if(isset($usr->state) && $usr->state=='CA'){echo 'selected';} ?>>California</option>
<option value="CO" <?php if(isset($usr->state) && $usr->state=='CO'){echo 'selected';} ?>>Colorado</option>
<option value="CT" <?php if(isset($usr->state) && $usr->state=='CT'){echo 'selected';} ?>>Connecticut</option>
*
*
*
</select>

我创建了这个函数:

public void select() {
Select drpState = new Select(driver.findElement(By.id("xstate")));

drpState.selectByValue("CA");
}

但我收到错误:

org.openqa.selenium.ElementNotVisibleException: element not interactable: Element is not currently visible and may not be manipulated
(Session info: chrome=75.0.3770.100)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PBX-WS2-SL2', ip: '10.30.10.54', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 74.0.3729.6 (255758eccf3d24..., userDataDir: C:\Users\DAYANA~1.SIL\AppDa...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:56255}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 75.0.3770.100, webStorageEnabled: true}
Session ID: 7b5fe4de6ccaace4b79ddee37685d7a2

最佳答案

试试这个

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("xstate")));

Select drpState = new Select(driver.findElement(By.id("xstate")));

drpState.selectByValue("CA");

关于java - 无法从下拉列表中选择值 : ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56838987/

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