Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Webdriver无法在遍历两个页面返回的页面上找到元素_Java_Selenium_Xpath_Selenium Webdriver - Fatal编程技术网

Java Webdriver无法在遍历两个页面返回的页面上找到元素

Java Webdriver无法在遍历两个页面返回的页面上找到元素,java,selenium,xpath,selenium-webdriver,Java,Selenium,Xpath,Selenium Webdriver,Webdriver似乎无法在其最初定位的页面上选择webelement(按钮),但在遍历多个页面时返回到同一页面,同一对象不会被selenium Webdriver定位 情况是,我在主页上添加了.isDisplayed()这样的方法来验证它- if (isElementPresent("(//input[@name='sbqq__editlines'])[1]") == true) { System.out.println("YES, reached on Quote page");

Webdriver似乎无法在其最初定位的页面上选择
webelement
(按钮),但在遍历多个页面时返回到同一页面,同一对象不会被
selenium Webdriver
定位

情况是,我在主页上添加了
.isDisplayed()
这样的方法来验证它-

if (isElementPresent("(//input[@name='sbqq__editlines'])[1]") == true)
{
    System.out.println("YES, reached on Quote page");
    if (objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).isDisplayed())
        {
        List<WebElement> rows = objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).findElements(By.xpath(".//tr"));
        List<WebElement> rows = objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).findElements(By.xpath(".//tr"));

...now if rows are present with text 'Requested' then a link has to be clicked on that row and workflow takes the user to multiple page of Apporval !


driver.findElement(By.xpath("//input[@value='Approve']")).click();

///Reaching back to QUOTE page now !            ---NOT WORKING FROM HERE !
    tmpElement = new WebDriverWait(driver, 100)
                .until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='sbqq__editlines'])[1]")));
    tmpElement = null;

}else{
        System.out.println("Didn't reached Quote Page !");
    }
if(isElementPresent((//input[@name='sbqq\uu editlines'])[1]“”==true)
{
System.out.println(“是的,在报价页上到达”);
if(objApprovalBlk.findelelement(By.xpath(“.//table[@class='list'])).isDisplayed())
{
List rows=objApprovalBlk.findElement(By.xpath(“.//table[@class='List'])).findElements(By.xpath(“.//tr”);
List rows=objApprovalBlk.findElement(By.xpath(“.//table[@class='List'])).findElements(By.xpath(“.//tr”);
…现在,如果存在文本为“Requested”的行,则必须单击该行上的链接,工作流会将用户带到Approval的多个页面!
driver.findElement(By.xpath(“//input[@value='Approve']”)。单击();
///现在返回到报价页!--从这里不工作!
tmpElement=新的WebDriverWait(驱动程序,100)
.until(ExpectedConditions.elementtobelickable(By.xpath(//input[@name='sbqq\uu editlines'])[1]);
tmpElement=null;
}否则{
System.out.println(“未到达报价页!”);
}
因此,返回主页时,无法识别相同的对象
//input[@name='sbqq\uu editlines'])[1]
。以下是我收到的例外情况:

org.openqa.selenium.TimeoutException:100秒后超时 正在等待元素可单击:By.xpath: //输入[@name='sbqq\uuu editlines'])[1]

我无法理解这背后的问题,是驱动程序引用了一个过时的对象,还是当我单击Quote主页上的链接时,它不是直接来自驱动程序对象,而是其他东西,因此我可能需要刷新驱动程序对象。我刚开始使用
selenium
,来自
HP UFT
后台,因此想到刷新对象是我对这个问题的第一次评估。

根据回答:

试用

  PageFactory.initElements(driver, this);

在基本页上执行任何活动之前。

这是分页链接吗?请尝试使用isElementPresent((//input[@name='sbqq\uu editlines'])[1])在使用tmpElement之前。检查您的元素是否可见。不,不是分页链接,但想想请求-批准页面,那里有提供批准的链接!因此我需要逐个单击可用链接以提供批准,每次批准后,控制返回主页!@peterpawar,当然让我尝试更新e、 但与此同时,有什么理由在之前使用“isElementPresent”吗?我将该条件用作同步,以便在继续进行任何操作之前,首先轻松打开主页!感谢@halfer对格式的深入了解(至少对我而言)!感谢@Kushal的回复。POM仍然需要在我的代码中实现,但您能否分享共享此方法的原因。我们是否可以假设驱动程序需要初始化(或刷新)使用最新的值,即使我们刚刚登录到一个页面并试图等待该页面完全加载时也是如此:
tmpElement=new-WebDriverWait(driver,100).until(ExpectedConditions.elementtobelickable(by.xpath(//input[@name='sbqq_ueditlines'][1]);
让我知道我是否遗漏了什么。