简体   繁体   English

单击按钮并在 Selenium java 中获取表格的大小

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

I am trying to learn selenium to find elements and I could not clicking the "Edit"buttons and Im trying the get the size of the rows of the table.我正在尝试学习 selenium 来查找元素,但我无法单击“编辑”按钮,我正在尝试获取表格行的大小。

Here is my code:这是我的代码:

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();

Here is the link that I am working: https://js.devexpress.com/Demos/WidgetsGallery/Demo/DataGrid/PopupEditing/Angular/Light/这是我正在工作的链接: 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();

Use webdriver wait and switchTo frame, you have to switch to iframe first to interacte elements inside the iframe.使用 webdriver wait 和 switchTo 帧,您必须先切换到 iframe 才能与 iframe 内部的元素交互。

once you finish, if you want to interact with elements outside iframe then you have to switch out of it first.完成后,如果您想与 iframe 之外的元素进行交互,那么您必须先退出它。

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

The element is present inside an iframe and you need to switch iframe first and then you will be able to interact with element.该元素存在于iframe ,您需要先切换iframe ,然后才能与元素交互。

To overcome synchronization issue you need to induce WebDriverWait() and wait for frameToBeAvailableAndSwitchToIt() and following locator.要克服同步问题,您需要诱导WebDriverWait()并等待frameToBeAvailableAndSwitchToIt()和跟随定位器。

To get the link details induce WebDriverWait() and wait for visibilityOfAllElementsLocatedBy() and following locator.要获取链接详细信息,请诱导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