selenium - 无法在表单类或 div 类中找到元素
问题描述
我无法在表单类或 div 类中找到元素:
//Tried this clicking on Source name.
driver.findElement(By.id("__BVID__62")).click();
//Typing into Source name.
driver.findElement(By.id("__BVID__63")).sendKeys(new String[]{"CNN"});
我试过这个:
driver.findElement(By.xpath("//input[contains(@class='form-control') and type='text']")).sendKeys("CNN");
HTML 代码:
<div class="card-body">
<fieldset id="_BVID__62" role="group" aria-labelledby="__BVID__62__BV_label" class="b-form-group form-group">
<legend id="_BVID__62__BV_label" class="col-form-label pt-0">Source Name</legend>
<div role="group" aria-labelledby="_BVID__62__BV_label" class="">
<input id="__BVID__63" type="text" class="form-control">
解决方案
使用此代码:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement input = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='card-body']/descendant::div/input[contains(@id,'BVID')]")));
input.sendKeys("CNN");
推荐阅读
- nested - Cortex-M3 SysTick 双中断
- c - 在 C 中使用 stat() 获取文件访问权限
- typescript - 接口中的通配符属性名称?
- reactjs - Agora.io Education_web 项目
- java - 无法在 Eclipse 中查看图像文件
- google-apps-script - 如何在 Apps Script 上超过 30 分钟时间
- php - 在邮件中显示来自 tinymce 编辑器的图像
- rasa - Rasa 网络聊天 + 泊坞窗显示空白
- php - 我可以编辑 Amelia wordpress 预订系统以在不预订的情况下创建新客户吗?
- discord - 有没有办法在 Discord 中获取某人的电子邮件?重要的