简体   繁体   中英

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

<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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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