简体   繁体   English

无法在selenium中单击表的元素

[英]Not able to click on element of table in selenium

I want to click on an element in a table the html code of element is following 我想点击元素的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>  

Following is screen short,after clicking on underwriting I am not able to click on motor. 以下是屏幕短,点击承销后我无法点击电机。 The code is working on a pc but not working on another one. 代码在PC上工作,但不在另一个上工作。 Please help me. 请帮我。
Code is bellow 代码如下

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(); 

在此输入图像描述

first try this : 先试试这个:

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

if this does not work, than try this: 如果这不起作用,那么试试这个:

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);

and than click on ur element like this 而不是像这样点击你的元素

elem.click();

if the element is not visible in screen, than first scroll to that element like below: 如果元素在屏幕中不可见,则首先滚动到该元素,如下所示:

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) + ");");

after element visible in ur screen, than click by normal driver click or javascript click. 在您的屏幕中可见元素后,点击正常的驱动程序点击或javascript点击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM