我的 handson 表有 200 多条记录。但我只能看到前 27 条记录,并且只能看到 25 列中的前 8 列。
以下是我尝试过的代码类型。
代码 1:
WebElement invoice=driver.findElement(By.xpath("//*[@id='ht_aeb2df21163d7999']/div[1]/div[1]/div[1]/table/tbody/tr[1]/td[7]/a/i")); int y=invoice.getLocation().y; int x=invoice.getLocation().x; Actions act=new Actions(driver); act.clickAndHold(invoice).dragAndDropBy(invoice,x,y).build().perform(); invoice.click();
代码 2:
Actions action=new Actions(driver); action.sendKeys(Keys.LEFT).perform(); action.sendKeys(Keys.LEFT).perform(); action.sendKeys(Keys.LEFT).perform();
代码 3:
JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("scroll(0, 750)");
最佳答案
我会尝试 javascript 方法,但将实际元素作为目标进行滚动。 scroll
函数以窗口为目标。
例如,我可以滚动 example here通过执行
document.querySelectorAll('.wtHolder')[0].scrollTop = 500
使用开发工具控制台。
关于java - 我正在尝试使用 selenium 网络驱动程序滚动 handson 表,但无法这样做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30045443/