- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我在 HTML 页面上有这个文本字段,它在模式框中接受 1-100 之间的数字。如果您输入一个大数字 -> 下面的 div 中会出现错误消息,并且类会分配给该 div。对于负数也是如此。无法输入文本,将该字段留空,然后在具有空字段的模式框中单击“确定”也会触发错误消息,如我之前描述的那样。
当我手动测试所有内容时,一切正常,我可以找到具有我之前提到的类的元素。
当我自动执行此操作时...我总是收到错误:没有这样的元素:无法定位元素:{“method”:“css选择器”,“selector”:“.class”}
当我在空字段中单击“确定”后检查是否存在错误消息时。
数字太大或为负数时,可以正确定位元素。
似乎单击了“确定”按钮,但未出现消息。因此,手动单击按钮和自动单击按钮之间存在差异。
你们中是否有人注意到过类似的情况,并且可以给我一些意见,告诉我可能是什么原因以及如何解决这个问题?
已经询问了一些同事,他们都不知道为什么会发生这种情况。
如果您需要任何其他信息,请告诉我。
谢谢
编辑:
<div class="classes" width="400px">
<div class="classes">
<h4 class="classes">Some text</h4>
<svg
stroke="currentColor"
fill="currentColor"
stroke-width="0"
viewBox="0 0 24 24"
class="classes"
size="20"
height="20"
width="20"
>
<path
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
></path>
</svg>
</div>
<div class="classes">
<form novalidate="" class="classes">
<h3 class="classes">Some text</h3>
<div class="">
<div class="classes">
<div class="classes">
<input
class="classes"
name="name"
type="number"
id="name"
step="any"
autocomplete="new-password"
value="70"
/>
</div>
<div class="classes">
HERE IS THE ERROR MESSAGE DISPLAYED
</div>
</div>
</div>
<div class="classes">
<button class="classes" type="button" id="cancel">
<p class="classes">Abbrechen</p></button
><button class="classes" type="submit" id="ok">
<p class="classes">Ok</p>
</button>
</div>
</form>
</div>
</div>
这是一些 Selenium 代码:
这是用所需输入填充字段的函数:
public void fillField(String input) {
driver.findElement(byId).click();
driver.findElement(byId2).click();
driver.findElement(byId2).clear();
driver.findElement(byId2).clear();
driver.findElement(byId2).sendKeys(input);
}
我们需要在这里清除该字段两次,因为由于某种原因,一次不能清除它。但目前这不是问题。
然后我们只需单击“确定”即可:
public void clickOk() {
driver.findElement(byOkModal).click();
}
但问题是,单击“确定”后并没有出现错误消息。手动单击时会出现。
还尝试了不同的等待方法,多次单击,移动鼠标并单击其他地方......没有任何效果......
最佳答案
正如人们之前提到的,将您的 Selenium 脚本放在这里会非常有帮助但你可以尝试这样的事情。
// Click ok here
// Wait for message to be displayed
WebDriverWait wait = new WebDriverWait();
wait.until(ExpectedConditions.visibilityOf(WebElement)).isDisplayed();
或者你创建方法然后在其他地方重用它
public boolean iSElementVisable(WebElement) {
return wait.until(ExpectedConditions. visibilityOf(WebElement)));
}
编辑:try-catch 可能有帮助
public boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
或流畅等待
public void waitUntilWebElement(final WebElement element) {
new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(3))
.until(d -> {
if(element.isDisplayed()) {
// do something
} else {
// do something
}
});
}
在此处了解有关流畅等待的更多信息:https://selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html
希望这有帮助。
关于java - 无法使用 Selenium WebDriver 定位现有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60228149/
我想在 Watir webdriver 中使用 selenium webdriver Actions。这可能吗? 也可以在 watir webdriver 中使用 java 代码。请帮忙。 我浏览了很
我正在使用 watir-webdriver 浏览我的网站并在不同的浏览器中抓取屏幕截图。 有时在 IE 中截取的屏幕截图大小合适,但颜色完全是黑色。同时运行的 Firefox 测试看起来很好。 bro
我已经编写了 driver.findElement(By.id("kfiDocumentLink")).click(); 用于单击“KFI 文档”按钮的代码。 请找到HTML代码。 Download
我有一个包含以下内容的 html 页面: This is Login page. Please click below link
我想获得页面加载异常,但仍然没有结果。 我使用implicitlyWait 设置计时器以抛出异常。 WebDriver driver = new FirefoxDriver(); driver.man
我正在使用具有 IE 特定应用程序的 Selenium Webdriver。我知道我们可以截取执行的截图。同样,是否有任何选项可以将 selenium 执行记录为视频? 最佳答案 WebDriver
Selenium WebDriver 如何克服同源策略? Selenium RC 中存在同源策略问题 最佳答案 First of all “Same Origin Policy” is introdu
我将如何从输入文件中提取文本?我尝试使用 XPath/CSSSelector 但我得到一个空文本,因为它是一个输入字段。 这是我的 html 代码: 结果:195 行中的 1 到 50
如何使用 WebDriver 自动验证码? 是否有其他方法可以使用 Webdriver 自动执行验证码? 最佳答案 您只能使用“alt”属性中的显示验证码值来自动化验证码。 在 WebElement
最近我开始学习 WebDriver,因为我工作的客户计划使用 WebDriver 来自动化 Web 应用程序。 我怀疑 WebDriver 如何在网页上定位其 ID 动态变化的元素(比如每次登录应用程
我发现 watir-webdriver 在一个非常大的页面上通过正则表达式定位元素非常慢,至少在 FF 8.0.1 中对我来说是这样。航类搜索结果页面示例(包含大约 50 个搜索结果,每个都是 htm
我有一个动态更改其文本的字段。我需要一种方法来等待文本被更改。我不知道会出现什么文本,但我知道当前那里有什么文本。所以我想等待它在元素中消失。有办法吗? 最佳答案 你可以试试ExpectedCondi
自从我使用 Firefox 升级到 3.0 beta 后,我就有了这个异常(exception)。 Exception in thread "main" java.lang.IllegalStateE
任何人都可以帮助我使用 Selenium webdriver 截取整页屏幕截图。我正在使用 c#/Nunit。我正在使用的当前方法不是完整的浏览器页面。 我正在使用下面的代码截取屏幕截图。 publi
我通过 WebDriver (Chrome) 从网页下载图像 // STEP 1 $driver->get($link); // STEP 2 $els=$driver->findElements(W
Selenium WebDriver 的默认隐式等待值是什么? selenium 文档说它是“0”,但是当我在一个全新的项目上调用 .findElement 时,DOM 上不存在元素,它似乎在一段时间
我正在使用 Webdriver 测试 Web 应用程序,大致如下所述。当测试通过时,一切都很好。但是,当其中一个测试失败时,我注意到以下 2 个问题。 a) 如果一个测试失败,则套件中的其余测试将超时
我正在使用 Selenium WebDriver 并遇到问题。 在 UI 中,WebDriver 可以看到元素,但无法执行任何操作,例如单击、键入、选择等。元素由 selenium 找到并作为 web
我在 Java 中使用 Web 驱动程序处理 UntrustedSSLcertificates 时陷入困境。 我创建了 Firefox 配置文件,如: FirefoxProfile profile =
选择的编程语言是 Java。我已经用 Java 编写了一个方法,我将 WebDriver 作为参数传递给它... public boolean myMethod(WebDriver webDriver
我是一名优秀的程序员,十分优秀!