鼠标悬停后点击
Click after mouse over
亲爱的,我需要一些关于此代码的帮助
首先:我需要让测试用例在
时通过if语句
driver.findElement(By.id("login:popupPanel-tr")).isDisplayed());
id
显示到运行 条件,if 不完成没有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 class mouseOver API 然后执行点击元素。
如果这有帮助,请告诉我。
亲爱的,我需要一些关于此代码的帮助
首先:我需要让测试用例在
时通过if语句driver.findElement(By.id("login:popupPanel-tr")).isDisplayed());
id
显示到运行 条件,if 不完成没有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 class mouseOver API 然后执行点击元素。 如果这有帮助,请告诉我。