簡體   English   中英

單擊按鈕並在 Selenium java 中獲取表格的大小

[英]Click the Button and get the size of table in Selenium java

我正在嘗試學習 selenium 來查找元素,但我無法單擊“編輯”按鈕,我正在嘗試獲取表格行的大小。

這是我的代碼:

System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/PopupEditing/Angular/Light/";
driver.get(baseUrl);
driver.manage().window().maximize();
TimeUnit.SECONDS.sleep(5);
List<WebElement> we = driver.findElements(By.linkText("Edit")); System.out.println(we.size());
we.get(1).click();

這是我正在工作的鏈接: https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/PopupEditing/Angular/Light/ 在此處輸入圖像描述

driver = new ChromeDriver();
driver.get("https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/PopupEditing/Angular/Light/");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
WebElement frame = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("demoFrame"))));
driver.switchTo().frame(frame);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[class=\"dx-link dx-link-edit\"]"))).click();

使用 webdriver wait 和 switchTo 幀,您必須先切換到 iframe 才能與 iframe 內部的元素交互。

完成后,如果您想與 iframe 之外的元素進行交互,那么您必須先退出它。

 driver.switchTo().defaultContent();
 //rest of your code

該元素存在於iframe ,您需要先切換iframe ,然后才能與元素交互。

要克服同步問題,您需要誘導WebDriverWait()並等待frameToBeAvailableAndSwitchToIt()和跟隨定位器。

要獲取鏈接詳細信息,請誘導WebDriverWait()並等待visibilityOfAllElementsLocatedBy()和以下定位器。

WebDriver driver = new ChromeDriver();
String baseUrl = "https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/PopupEditing/Angular/Light/";
driver.get(baseUrl);
driver.manage().window().maximize();        
new WebDiverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("demoFrame")));
List<WebElement> we =new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.linkText("Edit")));
System.out.println(we.size());
we.get(1).click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM