gpt4 book ai didi

java - Selenium moveToElement() 读取工具提示不起作用

转载 作者:行者123 更新时间:2023-11-30 02:29:10 25 4
gpt4 key购买 nike

将无效的文件类型添加到文件上传部分后,验证消息将显示为工具提示,即使使用 moveToElement() 后我也无法验证工具提示;

这是我用来使工具提示可见的代码

`driver.findElement(By.xpath(""//input[@type='file']"").sendKeys(invalidLicenseFileType.txt);
Actions actions = new Actions(driver);
actions.moveToElement(//*[contains(@class, 'fieldlabel-content')]).build().perform();`

ToolTip validation message image

HTML 代码:

<div class="fieldlabel-content">
<label class="fileinput fileinput--invalid">
<div class="fileinput-cell fileinput-cell-input">
<input placeholder="Choose a .license file..." accept=".license" value="" tabindex="0" type="file">
<div class="fileinput-description">
File:
<span class="fileinput-description-file">
<span class="icon fa fa-file-text-o"></span>
invalidLicenseFileType.txt
</span>
</div>
</div>
<div class = "popup popup--theme-error popup--position-top popup--hover" style="top: 131px; left: 399px;">Validation message for uploading invalid file type.</div>
</label>

最佳答案

我有两个建议来解决这个问题:

首先:使用 JavaScript

WebElement element = driver.findElement(By.xpath("value of xpath")).sendKeys(invalidLicenseFileType.txt);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].onmouseover()", element);

在最后一行中,您可以指定要悬停在其上的 WebElement 的 xpath 来代替 element

第二:使用操作

尝试在 Actions 类中使用 clickAndHold 代替 moveToElement

WebElement element = driver.findElement(By.xpath("value of xpath")).sendKeys(invalidLicenseFileType.txt);
Actions actions = new Actions(driver);
actions.clickAndHold(//*[contains(@class, 'fieldlabel-content')]).build().perform();

关于java - Selenium moveToElement() 读取工具提示不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711436/

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