如何使用硒的webdriver
问题描述:
我想用这个site如何使用硒的webdriver
1成执行水平滚动)首先降低了浏览器的大小做水平滚动,直到你会看到表的滚动条。
我曾与下面的代码完成,但它并没有为我工作。
driver.get("https://weather.com/en-IN/weather/5day/l/USID0011:1:US");
Dimension d = new Dimension(521,628);
driver.manage().window().setSize(d);
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
我的代码至今运作良好,但我的执行正从这里停止。
我试过这个滚动问题Action class
但同样的问题正在被复制。
Actions act = new Actions(driver);
WebElement horizontal_scroll = driver.findElement(By.xpath("//div[@id='twc-scrollabe']/table"));
act.clickAndHold(horizontal_scroll).moveByOffset(40, 0).release().perform();
我有这个试试下面的方法也有,但是同样的问题是如何复制的。
WebElement horizontal_scroll = driver.findElement(By.xpath("//div[@id='twc-scrollabe']/table"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(driver.execute_script("arguments[0].scrollIntoView()", horizontal_scroll));
在我的申请,我无法用此方法去,因为没有style
属性可里面table
标签。
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById(''twc-scrollabe').setAttribute('style', 'position: relative; top: 0px; left: -658px; width: 1461px;')");
谁能帮助我在这个问题上?
您的帮助,必须认识。
最好的问候,
Jainish卡帕迪亚
答
下面简单的使用水平滚动
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.querySelector('table th:last-child').scrollIntoView();");
这应该允许滚动到表的最后一栏
+1
我有这个代码实现。 'WebElement horizontal_scroll = driver.findElement(By.xpath(“// table [@ class ='twc-table'] /..// following :: th [@ id ='humidity']”)); \t((JavascriptExecutor)驱动程序).executeScript( “参数[0] .scrollIntoView(真);”,horizontal_scroll);' –
我怀疑你'// DIV [@ id ='twc-scrollable']/table'指向滚动条。如果你有,你应该向滚动,像一个表格单元格的一些特定元素,那么你应该找**的**细胞和'scrollIntoView()'就可以了。不是桌子本身,因为这大概已经在看。 –
只需将'scrollIntoView'应用于表格的最后一个'th'元素即可...... – Andersson
@ M.Prokhorov但滚动条位于表格内,我无法找到仅滚动条。你有没有尝试过这样做? –