下午好,
我在带有JAVA的Eclipse中使用Selenium WebDriver,并且正在创建一个自动化过程,该过程的最初部分需要用户登录名和密码,直到该部分我可以使用下面的代码来完成
package automationFramework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Registro {
public static void main(String[] args) {
//º) NECESSÁRIO INSTÂNCIAR O CHROME WEBDRIVER NO INÍCIO DO PROCESSO
String exePath = "C:\\Users\\RAFSOUZA\\Downloads\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
WebDriver driver = new ChromeDriver();
//º) MAXIMIZA TELA E AGUARDA ALGUNS SEGUNDOS
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//º) ABRE NAVEGADOR E VAI ATÉ O SITE ESCOLHIDO
driver.get("https://www.credenciados.detran.rs.gov.br");
//º) 1º TELA - INSERE CRENDECIAIS DO USUÁRIO
WebElement iptboxCred = driver.findElement(By.name("credenciado"));
iptboxCred.sendKeys("XXXXXXX");
WebElement iptboxUser = driver.findElement(By.name("usuario"));
iptboxUser.sendKeys("XXXXXXX");
WebElement iptboxSenha = driver.findElement(By.name("senha"));
iptboxSenha.sendKeys("XXXXXX");
//Executa o Login no botão OK do site
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver)
.executeScript("javascript:logon();");
}
}
}
单击RECONET按钮时,站点将打开浏览器的新选项卡,其中将填充剩余数据,而这就是我被卡住的位置,我无法创建单击按钮的代码来打开新选项卡
<p id="menuReconet" class="menuOut" onclick="SwitchMenu('subReconet')" onmouseover="ChangeClass('menuReconet','menuOver')" onmouseout="ChangeClass('menuReconet','menuOut')">
<a href="redirectSng.jsp" target="_blank">RECONET</a>
</p>
我正试图通过这种方式做到这一点:
JavascriptExecutor exeBtnReconet = (JavascriptExecutor)driver; exeBtnReconet.executeScript("document.getElementById('menuReconet').click(););
我在Console Eclipse中收到此错误:
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: Cannot read property 'click' of null