错误消息"无法找到元素"

时间:2018-03-13 06:43:22

标签: javascript selenium

我正在尝试识别一个使用XPATH在类下定义的id的按钮,但它抛出一条错误消息"无法找到元素"。 课程详情:

<div class="aui-button-holder inputBtn" id="aui_3_4_0_1_202"> 
    <span class="aui-button aui-button-submit" id="aui_3_4_0_1_201"> 
    <span class="aui-button-content" id="aui_3_4_0_1_200">     
    <input class="aui-button-input aui-button-input-submit" type="submit" value="Sign In" id="aui_3_4_0_1_180">     
    </span>     
    </span>     
    <input type="button" class="aui-button-input aui-button-input-submit" onclick="parent.location='/web/offers/reg'" value="Register">         
</div>

我编写的代码:

WebElement login=driver.findElement(By.xpath("//div[@id='aui_3_4_0_1_180']"));    
login.click();

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id='aui_3_4_0_1_180']"}

3 个答案:

答案 0 :(得分:0)

id不属于div,它是输入的id。

您可以改为使用(BrowserDetect.version == 9)

答案 1 :(得分:0)

您必须等待元素可点击:

WebDriverWait wait = new WebDriverWait(driver, 10); 
wait.until(ExpectedConditions.elementToBeClickable
(driver.findElement(By.xpath("//div[@id='aui_3_4_0_1_180']")));

答案 2 :(得分:0)

您可以尝试使用此XPath://div[@class="aui-button-holder inputBtn"]/*[@value="Sign In"]