java - iframe 点击在 Chrome 中不起作用
问题描述
public void nmb_message() throws IOException, InterruptedException {
WebDriver driver = Driverfactory.open("chrome", ".com");
Logins login = new Logins();
login.campaignqa();
String actualTitle = driver.getTitle();
String expectedTitle = "SmartFocus";
(new Actions(driver)).dragAndDrop(element2, target2).perform();
WebElement myDynamicElement2 = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.xpath( "//*[contains(text(), 'Add a picture')]")));
myDynamicElement2.click();
Thread.sleep(3000);
driver.switchTo().frame(driver.findElement(By.cssSelector("#msg-editor-imagelib-iframe")));
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='item-39571']/div/div[2]")).click(); Thread.sleep(15000L); driver.findElement(By.xpath( "//iframe[@class=contains(text(), 'Apply & close)]")).click(); }}
我已经能够切换到 iframe ,然后单击图像选择 [如图 1 所示],然后无法单击 div-preview 按钮 [如图 2 - 蓝色按钮],即“应用和关闭”。
使用 ""driver.findElement(By.xpath( "//iframe[@class=contains(text(), 'Apply & close)]")).click();" 或使用 Id 或 css 选择器。
任何想法 ?
<div id="msg-editor-imagelib" class="popup-container" style="visibility: visible; opacity: 1;">
<div class="popup-mask"></div>
<div class="popup confirm restrict">
<div class="popup-header">
<span class="popup-header-title left">Add image</span>
<span class="popup-header-close"></span>
</div>
<div class="popup-content">
<div class="switch-container">
<div class="image-popup-content">
</div>
<div class="options-panel-overlay open"></div>
<div class="options-panel-container empty open">
<div class="border-right"></div>
<div class="img-container">
<div class="notification info">You can select an image either by selecting an image from Smartfocus Image Library or enter a distant URL. Once selected, this panel will give you details like ALT tags and link.</div>
</div>
<div class="options-panel-container edition visible open">
<div class="border-right"></div>
<div class="image-preview-container">
<div class="custom-image-preview-placeholder onthefly-placeholder onthefly-placeholder--imghelper hidden">
<img id="image-popup-image-preview" src="http://p2itgtre.emv2.com/IL/5/4/8/1101011548/1735085964.jpg">
</div>
<div class="inputs-block">
<span class="image-label">1735085964</span>
<div id="image-source" class="input-header">
<span>Source</span>
<span class="source">Image Library</span>
</div>
<div class="input-header">
<span>Alternative tag</span>
</div>
<input id="alt-tag-input" type="text" value="">
<div id="alt-tag-helper" class="icon help cue sf-icon sf-icon--small"></div>
</div>
<div class="button-container">
<div id="image-popup-options-apply" class="submit blue popup-confirm">Apply & close</div>
</div>
</div>
</div>
</div>
解决方案
尝试使用此 Xpath 应用并关闭
.//*[@id='image-popup-options-apply']
推荐阅读
- django - 尝试删除模型实例时出现无效的列名错误
- c# - Regex.Split 考虑字母和破折号
- android - 从 Editext 获取输入
- typescript - 并非所有代码路径都在 Firebase 云函数中返回值
- c++ - 如何仅使用标准库将 C++ 对象写入文件
- javascript - 如何处理嵌套表单的条件验证?
- css - 如何将特定于浏览器的 CSS 组合在一起?
- asp.net - 无法使用 NLog 从托管在 Windows Elastic Beanstalk 机器上的 ASP.Net 应用程序将日志写入 AWS cloudwatch
- google-compute-engine - 在 GCP 中克隆 windows 虚拟机的最佳方法
- python - 熊猫 groupby 中的 NaN 项目是否后跟聚合,包括类别列的预期行为?