How to determine coordinates of an element with Watir Webdriver?

混江龙づ霸主 提交于 2019-12-11 06:53:01

问题


I have a problem. While parsing a page, a pop-up window appears and blocks access to html. I tried to click on the pop-up, but it re-directs me to a new page, and I have no clue how to get to the upper right area of the pop-up to close it. My question is how to determine the coordinates of that element? None of the related issues raised here at Stackoverflow helped me find a solutions, so assistance would be very much appreciated.


回答1:


Why do you need the actual coordinates? That seems like a bad idea given it could move or have different results on different screen sizes (responsive designs). You'd be better off finding the class / id of the close button and calling browser.button(class: 'close').click or browser.link(class: 'close').click.

If you need help determining the class of the close button, open your browser and enable developer tools / console. They all have an inspector tool now to select the element and find all classes & ids.

In the unlikely event there are no classes or ids it may have a data attribute you could work off.




回答2:


If the pop-up is a regular browser window you can close it by index. Your main window has index 0. So the pop-up has index 1.

if browser.window(:index => 1).exists?
     browser.window(:index => 1).close
end


来源:https://stackoverflow.com/questions/45345101/how-to-determine-coordinates-of-an-element-with-watir-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!