1
I am using Selenium to automate the browser user action. I am using the HtmlUnitDriver
, not to open the browser and not have to point a .exe
.
The page I am doing, will show the components according to values selected in combos. When I change the second combo it is that the problems begin, because it does not find the id
of the next.
I realized that the HTML code at the moment is different and so does not find, I’m just not able to find a solution to it. I’ve used the wait
on terms, thread.sleep
, find the element by Xpath, none of this solved for me.
Code:
public static void main(String[] args) throws InterruptedException {
HtmlUnitDriver driver = new HtmlUnitDriver(true);
try{
driver.get("https://www.fazenda.sp.gov.br/guiasinternet/Gare/Paginas/Gare.aspx");
driver.findElement(By.id("ReceitaTipo")).click();
{
WebElement dropdown = driver.findElement(By.id("ReceitaTipo"));
dropdown.findElement(By.xpath("//option[. = 'GNRE']")).click();
}
//printar código fonte da pagina
System.out.println(driver.getPageSource());
Thread.sleep(5000);
driver.findElement(By.id("CodigoReceita")).click();
{
WebElement dropdown = driver.findElement(By.id("CodigoReceita"));
dropdown.findElement(By.xpath("//option[. = '10002.1 - Energia Elétrica']")).click();
}
//A partir daqui para de funcionar
System.out.println(driver.getPageSource());
driver.findElement(By.id("CnpjCpf")).click();
driver.findElement(By.id("CnpjCpf")).sendKeys("087.271.516-54");
driver.quit();
}catch(Exception e){
e.printStackTrace();
}
}