【发布时间】:2017-09-25 14:24:49
【问题描述】:
我发现很难从组合框元素中选择项目。这个组合框有些不同。当我向下拖动项目时,我可以看到项目的实际值(即 aria-activedescendant="react-select-4--option-3")。选择特定项目后,值已更改为“aria-activedescendant="react-select-4--value"”。请建议我单击该项目的最佳解决方案。您必须在 html 代码下的输入部分中特别注意此“aria-activedescendant="react-select-4--value"”。
尝试使用以下代码。我只能单击组合框元素,但不能单击该值。我使用 id="react-select-4--value" 来单击组合框,它错误为“元素不可点击”。从技术上讲,系统理解错误。
public void ScrollAndClickOnElement(String loacator,String LocatorValue)
{
WebElement element = null;
if(loacator.equalsIgnoreCase("cssSelector"))
element = driver.findElement(By.cssSelector(LocatorValue));
else if(loacator.equalsIgnoreCase("xpath"))
element = driver.findElement(By.xpath(LocatorValue));
else if(loacator.equalsIgnoreCase("id"))
element = driver.findElement(By.id(LocatorValue));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);",element);
element.click();
}
public void WaitAndClickElement(String locatorType,String locatorVaue)
{
WebDriverWait wait = new WebDriverWait(driver,50);
if(locatorType.equalsIgnoreCase("cssSelector"))
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(locatorVaue))).click();
else if(locatorType.equalsIgnoreCase("xpath"))
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locatorVaue))).click();
else if(locatorType.equalsIgnoreCase("id"))
wait.until(ExpectedConditions.elementToBeClickable(By.id(locatorVaue))).click();
}
ScrollAndClickOnElement("id", AssessmentPageData.ElevatorManufacturer);
WaitAndClickElement("cssSelector",AssessmentPageData.Appollo);
参考了这个link并使用了'select'方法,但它错误为“元素应该是“select”但是是“span””
【问题讨论】:
-
提供更多信息: 1. 您的具体测试步骤是什么? 2. 什么对你有用?显示代码。 3. 你卡在哪里了?提供错误堆栈跟踪。
-
感谢您的回复。我想从组合框中选择一个项目。我被卡住了,因为无法从 html 代码中传递正确的参数,因为值正在动态更改,正如我在上面的示例中所解释的那样。对于上面相同的html代码,如果有人提出不同的解决方案,那就太好了。
-
浏览您的 cmets 我了解单击组合框时,组合框项目之一的
id从react-select-4--option-3更改为react-select-4--value。但是点击更新的id有什么问题呢? -
好的,所以您正在尝试使用定位器的存储值。我认为你仍然可以使用 cssSelector 来做到这一点。但是你必须确切地知道变化的模式。你能提供更多组合框项的 HTML DOM 吗?
-
请在附件中找到组合框的 HTML DOM。如果让您感到困惑,我很抱歉。