2017-02-28 196 views
0

我想用這個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卡帕迪亞

+0

我懷疑你'// DIV [@ id ='twc-scrollable']/table'指向滾動條。如果你有,你應該向滾動,像一個表格單元格的一些特定元素,那麼你應該找**的**細胞和'scrollIntoView()'就可以了。不是桌子本身,因爲這大概已經在看。 –

+1

只需將'scrollIntoView'應用於表格的最後一個'th'元素即可...... – Andersson

+0

@ M.Prokhorov但滾動條位於表格內,我無法找到僅滾動條。你有沒有嘗試過這樣做? –

回答

2

下面簡單的使用水平滾動

JavascriptExecutor jse = (JavascriptExecutor) driver;  
jse.executeScript("document.querySelector('table th:last-child').scrollIntoView();"); 

這應該允許滾動到表的最後一欄

+1

我有這個代碼實現。 'WebElement horizo​​ntal_scroll = driver.findElement(By.xpath(「// table [@ class ='twc-table'] /..// following :: th [@ id ='humidity']」)); \t((JavascriptExecutor)驅動程序).executeScript( 「參數[0] .scrollIntoView(真);」,horizo​​ntal_scroll);' –