Я был с элементом , который не был прикреплен к документу страницы в моем скрипте Java для автоматизации с использованием SeleniumWebDriver.
Я искал в Интернете и обнаружил нижеприведенный скрипт, который исправил ошибку *Элемент 1005 * не прикреплен к документу страницы.
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;
}
}
}
Я продолжил процесс автоматизации и сразу же после вышеописанного сценария добавил код ниже, чтобы выбрать параметр в списке DropDown.
Select status = new Select(driver.findElement(By.id("cboStatus")));
В этот момент Eclipse отображает сообщение об ошибке: Код недоступен.
Я искал в Интернете, но ничего не нашел в сообщении об ошибке, касающемся SeleniumWebDriver.
Здесьполный код и сообщение об ошибке, отображаемое 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 {
}}
![Unreachable Code](https://i.stack.imgur.com/t0JLH.jpg)