2016-04-28 37 views
1

我想點擊一個元素在表中單擊表的元素元素的HTML代碼如下無法硒

<A onclick="return A_MENUS[0].onclick(4);" onmouseover=A_MENUS[0].onmouseover(4); onmousedown=A_MENUS[0].onmousedown(4); onmouseout=A_MENUS[0].onmouseout(4); id=e0_4o class=m0l1oout style="HEIGHT: 20px; WIDTH: 250px; POSITION: absolute; LEFT: 600px; Z-INDEX: 4; TOP: 98px; VISIBILITY: hidden" href="WebMenu.aspx"><DIV id=e0_4i class=m0l1iout>Start Proposal</DIV></A> 

以下是屏幕短,點擊承保後,我不能點擊電機。代碼在一臺電腦上工作,但不能在另一臺電腦上工作。請幫幫我。
代碼爲波紋管

wait = new WebDriverWait(wDriver, 150); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("home"))); 
wDriver.findElement(By.id("home")).click(); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("e0_5991o"))); 
wDriver.findElement(By.id("e0_5991o")).click(); 
customSleep(1000); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("e0_6101o"))); 
wDriver.findElement(By.id("e0_6101o")).click(); 
customSleep(1000); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("e0_6128o"))); 
wDriver.findElement(By.id("e0_6128o")).click(); 

enter image description here

+0

您是否嘗試過最大化瀏覽器窗口? – alecxe

回答

0

第一次嘗試這樣的:

(JavascriptExecutor(webdriver)).executeScript("document.getElementById('ur id').click();"); 

如果這行不通,比試試這個:

WebElement elem = driver.findElement(By.xpath("ur xpath"));//u may use by id or by class as ur wish 
String makeVisible = "arguments[0].style.visibility='visible';"; 
((JavascriptExecutor) driver).executeScript(makeVisible, elem); 

,比點擊烏爾像這樣的元素

elem.click(); 

如果元素是不是在屏幕上可見,比第一滾動到該元素象下面這樣:

JavascriptExecutor js = (JavascriptExecutor)driver; 
WebElement elem = driver.findElement(By.xpath("ur xpath")); 

//this line will scroll down to make element visible 
js.executeScript("window.scrollTo(" + elem.getLocation().x + "," +(elem.getLocation().y- 100) + ");"); 

元素烏爾屏幕上可見,比點擊通過正常駕駛點擊或JavaScript後點擊。

+0

@Shik這是工作還是還有什麼? – noor

+0

謝謝,但它不起作用給以下錯誤 – Shik

+0

謝謝,但它不起作用給以下錯誤 org.openqa.selenium.WebDriverException:JavaScript錯誤 代碼是 JavascriptExecutor jsExec =(JavascriptExecutor)wDriver; jsExec.executeScript(「document.getElementById('e0_5991o')[0] .click();」); – Shik