2016-04-28 34 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