我正在寻求一些建议。我目前正在尝试使用 selenium (Java) 为角度应用程序创建端到端测试。由于页面上的动态元素,我认为我不需要提及这个过程有多么痛苦。
我看过使用 NgWebDriver。但我对这种方法有疑问。我在页面上的所有元素如下所示:
<button _ngcontent-tmh-c54="" id="addNewPartnerSystem" pbutton="" label="Add New Partner System" type="button" class="p-element ui-button p-button p-component ng-star-inserted"><span class="p-button-label">Add New Partner System</span></button>
我尝试使用开发人员提供的 id,在本例中为“addNewPartnerSystem”,但 selenium 显示未找到元素错误。
任何帮助将不胜感激。谢谢!
回答1
由于您的页面是动态呈现的并且假设您选择的 XPath 是正确的,因此您需要等到页面加载完毕。 Thread.sleep(milliseconds) 可以解决问题。
回答2
您已尝试以下解决方案
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
elem = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("Xpath")));
elem.click();
或者
WebElement element = driver.findElement(By.id("id"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
让我知道这是否不适合您
回答3
似乎我所要做的就是在 iFrame 之间切换。感谢您的意见和建议