gpt4 book ai didi

java - 鼠标悬停后点击

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:48 25 4
gpt4 key购买 nike

亲爱的,我需要一些关于此代码的帮助

第一:我需要让测试用例通过 if 语句

driver.findElement(By.id("login:popupPanel-tr")).isDisplayed());

id 显示以运行条件,如果不完成没有 if 条件的测试用例

第二:我需要单击该元素

driver.findElement(By.id("home:regNew")).click();

当我执行此操作时,鼠标悬停后,它不会单击并且测试用例失败

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import java.sql.*;

driver.findElement(By.id("login:username")).clear();
driver.findElement(By.id("login:username")).sendKeys("sarasf");
driver.findElement(By.id("login:password")).clear();
driver.findElement(By.id("login:password")).sendKeys("P@ssw0rd");
driver.findElement(By.id("login:login")).click();

if (driver.findElement(By.id("login:popupPanel-tr")).isDisplayed()) {
driver.findElement(By.id("login:j_id54")).click();
Thread.sleep(3000);
driver.findElement(By.id("login:username")).clear();
driver.findElement(By.id("login:username")).sendKeys("abasiouny_shop");
Thread.sleep(1000);
driver.findElement(By.id("login:password")).clear();
driver.findElement(By.id("login:password")).sendKeys("passw0rd");
Thread.sleep(1000);
driver.findElement(By.id("login:login")).click();
Thread.sleep(30000);
Actions action = new Actions(driver);
WebElement subElement = driver.findElement(By.cssSelector("p.service"));
action.moveToElement(subElement);
action.click();
action.perform();
Thread.sleep(2000);
assertEquals("جديد", driver.findElement(By.id("home:regNew")).getText());
}else{
Thread.sleep(30000);
Thread.sleep(2000);
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.cssSelector("p.service")); action.moveToElement(element).moveToElement(driver.findElement(By.cssSelector ("p.service"))).build().perform();
Thread.sleep(2000);
driver.findElement(By.id("home:regNew")).click();
}

最佳答案

1)是什么阻止你这样做?

if(driver.findElement(By.id("login:popupPanel-tr")).isDisplayed())
{//condition
}

2)您是说鼠标悬停后会出现一个元素,您需要单击该元素吗?如果是这种情况,那么您需要使用 Actions 类 mouseOver API,然后执行对元素的单击。让我知道这是否有帮助。

关于java - 鼠标悬停后点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28341786/

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