我编写了一个测试,以将鼠标悬停在其下方具有链接的Element上,然后单击subElement。我不断收到NullPointerException。它以前已经工作过,然后又停止工作了。
Actions mouseHover = new Actions(driver);
mouseHover.moveToElement(ParentElement);
mouseHover.moveToElement(subElement);
mouseHover.click(subElement);
答案 0 :(得分:0)
它可能试图在元素出现之前单击它。尝试使用Web驱动程序,然后再移至子元素。 (由于它以前可以工作,所以我想应该是问题所在)
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.LOCATOR("subelement")));
看起来像
Actions mouseHover = new Actions(driver);
mouseHover.moveToElement(ParentElement);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.LOCATOR("subelement")));
mouseHover.moveToElement(subElement);
mouseHover.click(subElement);
Cheerz
答案 1 :(得分:0)
根据您的代码尝试,您没有为鼠标悬停调用import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
//other lines of code
Actions mouseHover = new Actions(driver);
mouseHover.moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOf(ParentElement)))).perform();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath(subElement))).click();
方法。您需要为元素引入 WebDriverWait ,并可以使用以下解决方案:
java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:882) at org.openqa.selenium.interactions.Actions.<init>(Actions.java:68)
由于您仍然看到以下错误:
Base
这意味着 WebDriver 实例,即 driver 不能从代码的这一部分访问。该问题可能与 driver 为 null 有关,因为您没有扩展 Test 类中的df=read.table(text="student Marks_1 Marks_2
A1 25 28
B1 22 24
C1 18 25",header=T)
# Create new column based on your formula
df$score=(df$Marks_2-df$Marks_1)^2
类。确保 driver 可以访问。