Selenium Webdriver xpath有时无法正常工作

时间:2018-07-07 10:51:26

标签: selenium selenium-webdriver xpath webdriver

我的XPath在与eclipse一起使用时不能在硒webdriver中使用。

    List<Tuple<string, int, decimal, string>> temporaryPriceList = new List<Tuple<string, int, decimal, string>>();
    // add sellers for productcategory
    foreach (string productID in cardProductIDs)
    {
        int indexCondition = GlobalVar.cardConditions.IndexOf(card.Item3);
        temporaryPriceList.AddRange(GetProductSellers(int.Parse(productID), minUserScore, idLanguage, indexCondition));
    }
    // sort
    temporaryPriceList.Sort((x, y) => x.Item3.CompareTo(y.Item3));
    // Process with the cheapest sellers

请帮助...。

2 个答案:

答案 0 :(得分:0)

尝试:

WebElement element1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("registerform201367343215309603094227submitbtn")));
            element1.click();

WebElement element2 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("registerform138887139815309587722027submitbtn")));
            element2.click();

答案 1 :(得分:0)

根据您的代码试用版,尚不清楚您的click()试用版是否在同一元素上。如果两次click()尝试都在同一个元素上,则需要诱使 WebDriverWait 来使元素变为可点击,并且您可以尝试以下解决方案:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[starts-with(@id,'registerform')][contains(@id,'submitbtn')]"))).click();