I was with a element is not attached to the page document in my Java script for automation using SeleniumWebDriver.
I searched the internet and found the script below that solved the error element is not attached to the page document.
boolean breakIt = true;
while (true) {
breakIt = true;
try {
Select acao = new Select(driver.findElement(By.id("cboSubMotivo")));
acao.selectByValue("519");
} catch (Exception e) {
if (e.getMessage().contains("element is not attached")) {
breakIt = false;
}
}
}
I continued the automation process and right after the above script, I added the code below to select an option within a DropDown List.
Select status = new Select(driver.findElement(By.id("cboStatus")));
At this point Eclipse displays the error message: Unreachable code.
I searched the internet but did not find anything about the error message regarding SeleniumWebDriver.
Here is the complete code and error message displayed by Eclipse.
public class validarStatus {
static WebDriver driver;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\chromedriver.exe");
}
@Test
public void logarBkoMais() throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.get("http://10.5.9.45/BKOMais_S86825EstrategiaBackOfficeClaroFixo");
driver.manage().window().maximize();
// Logar BkoMais
driver.findElement(By.id("matricula_I")).sendKeys("844502");
driver.findElement(By.id("senha_I")).sendKeys("Pw34Jdt#*");
driver.findElement(By.id("bt_entrar")).click();
// Logar na Estratégia
driver.findElement(By.id("mn_backoffice")).click();
driver.findElement(By.id("mn_bkoffice_prod_203")).click();// Produto
driver.findElement(By.id("mn_bkoffice_est_57")).click();// Estratégia
// Selecionado a atividade
Select atividade = new Select(driver.findElement(By.id("cboAtividade")));
atividade.selectByIndex(3);
// Registro >> Novo
Thread.sleep(500);
driver.findElement(By.id("mn_registro")).click();
driver.findElement(By.id("mn_novo_caso")).click();
// Cod Os Estratégia VREL
String CodOs = driver.findElement(By.xpath("//*[@id=\"content\"]/div[1]/fieldset[1]/div[2]/div[3]/span"))
.getText();
System.out.println(CodOs);
// Campo Análise de Contrato
Select analiseContrato = new Select(driver.findElement(By.id("cboMotivo")));
analiseContrato.selectByIndex(5);
// Campo Ação
boolean breakIt = true;
while (true) {
breakIt = true;
try {
Select acao = new Select(driver.findElement(By.id("cboSubMotivo")));
acao.selectByValue("519");
} catch (Exception e) {
if (e.getMessage().contains("element is not attached")) {
breakIt = false;
}
}
}
Select status = new Select(driver.findElement(By.id("cboStatus")));
}
@After
public void tearDown() throws Exception {
}}