how can I get the text of a hidden element in watir - watir

The html element is p, its attribute style="display:none;"
when the mouse move on the element,it is visible. How can I get the text of p in watir? Thank you!

Try:
#browser.p(:style, 'display:none;').fire_event 'mouseover
#browser.p(:style, 'display:none;').click #change to visible element you want to click
fire_event 'mouseover' acts as if your mouse is hovering over the element

Related

How to "scroll up" in div using selenium in python?

I am trying to scrape job details in LinkedIn. As per now, I am able to scroll till the end of list.
code:
#scrolling till buttom of page(online job section)
target = driver.find_element_by_xpath('//div[#class="jobs-search-results jobs-search-results--is-two-pane"]')
time.sleep(1)
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', target)
driver.implicitly_wait(1)
time.sleep(1)
now I want to scroll up to the top of the div.
I want to scroll up in div shown as red rectangle:
Scrolling to top of the page in Python using Selenium
Scroll Element into View with Selenium
There is 2 main way to do that:
Firstly, you can locate the element(at the top of your DOM view) in the DOM and then scrolling up until you find the element
element = driver.find_element_by_xpath("element_xpath")
driver.execute_script("return arguments[0].scrollIntoView(true);", element)
Secondly, you can easily use CTRL+HOME for scrolling to the top of the page with the help of Keys
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
But in your situation which dealing with JavaScript DOM, recommended way is the first one.
There are many ways to do this, here is one way:
driver.execute_script("window.scrollTo(0, 0);")
Alternatively you can scroll up with the mouse:
import pyautogui
pyautogui.scroll(10)

Different behavor of a tooptip for different mouse events in richfaces is possible?

Is there any way to make a tooptip behave differently deppending on if a mouse is over the element or it is clicked?
I need to have the same element working as a tooltip if the mouse is over and to open a popup panel if the mouse is clicked.
I could do it easily if using separated elements, but i need to use the same.

Setting drag mode over QGraphicsScene with QGraphicsWebView() in it

I have:
self.setScene(QtGui.QGraphicsScene(self))
self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
where self is QGraphicsView. I am opening my svg in QGraphicsWebView() because of it's interactivity like this:
s = self.scene()
s.clear()
self.resetTransform()
self.webview = QGraphicsWebView()
self.webview.load(QtCore.QUrl(path_to_my_svg))
self.webview.setFlags(QtGui.QGraphicsItem.ItemClipsToShape)
self.webview.setCacheMode(QtGui.QGraphicsItem.NoCache)
self.webview.setZValue(0)
s.addItem(self.webview)
Zooming works fine, but when I click over webview item in order to drag it, nothing happens except cursor is changed to text cursor. I can drag svg only when I open it like self.svgItem = QtSvg.QGraphicsSvgItem(path_to_my_svg) but in that case it's rendered as static image so I lose interactivity in svg(mouseover, mouseout in svg elements)...
EDIT based on xndrme's comment:
As he suggested SHIFT+mouse left click works well, but it drags the whole SVG which is inside self.webview. Apparently I've thought that when I zoom with mouse scroll svg gets zoomed, but actually self.webview is the one that gets zoomed and scroll bars appears. So, what I've actually need to know is how to drag the whole self.webview within its scroll bar boundaries (with left mouse click)

Watir- How can I put a hover on any HTML element

I have a web application, in that application the head menus open when we move mouse on to that (I don't want to click on that head menus because clicking on that menus redirect the page to another page).
On mouse over it opens a menu list, I will be able to select the menu item but not able to hover on to the head menu so that a drop-down menu list can appear.
fire_event("onmouseover") is not working, it is only flashing that menu(element) but not opening the drop down menu list.
Can any one give me the solution How can I put hover on to any HTML element please.
Well, there is #hover method:
browser.element(:how => what).hover
And this could also help: How to find out which JavaScript events fired?
For some reason .hover doesn't work for me, but this one does:
browser.element(how: what).fire_event(:mouseover)
No idea why.

How to create a DHTML menu?

I need to create a DHTML menu with the specified features, but I can't figure out how to do it. Here's what I need:
All items are layed out horizontally. If they would be wider than the screen, two little arrows appear on the right side of the menu that allow to scroll it. Something like this:
+--------+--------+-------+---+---+
| Item 1 | Item 2 | Item 3| < | > |
+--------+--------+-------+---+---+
Menu items should be clickable anywhere in the cell. They should stretch both vertically and horizontally to the contents. The text in the items should be centered both vertically and horizontally. The menu should work in IE7/Opera/FF/Safari.
The scrolling is the easy part - I just place it all in a container (say, a <div>), set the container to overflow: hidden and then play around in Javascript with clientWidth, scrollWidth and scrollLeft. That I've figured out and have already tried.
But how to make the menu items so stretchy, clickable anywhere and centered text?
Try the CSS below:
#menu {
display: table;
}
#menu a {
display:table-cell;
vertical-align:middle;
}
And then format your menu like:
<div id="menu">
normal text
<big>large text</big>
<span style="line-height:100px;">very tall text</span>
</div>
This will force vertical alignment and prevent the links from wrapping. Let us know how it works out.
OK, I talked with my superiors and they decided that it might be OK that you cannot right-click a menu item and select "Open in New Window". If this requirement is dropped, then I'm not bound to <a> elements for links. With JavaScript I can turn anything into a link. Thus, I choose you, pikachoo <table>!
Yap, it's a heresy, but it works. More specifically, it's the only construct that I can think of that can do all of the following at the same time:
Center text horizontally and vertically;
Stretch to contents horizontally and vertically;
Not wrap to next line when items are starting to overflow.
Anything else that can do the same will probably be more convulted anyway. And before anyone has the idea - no, I don't need search engine support. It's an internal web application. It'd be pretty bad if Google could index that...
clickable anywhere is easy: you can either bind the onclick event trigger (and hopefully some cursor styling) to the atomic cell element, or you can make the atomic cell elements <a> tags (or more likely wrap these in <li>) and link and style appropriately (padding, margin, foo).
e.g. case 1:
<ul id="menu"><li class="item" onclick="foo()" style="cursor:pointer; cursor:hand; padding:1em; margin:1px; float: left;">FOO!</li></ul>
(obviously I don't really recommend inline styling or script handlers but you get the idea)
Applying padding will effectively centre the text, and having no width assigned they'll naturally stretch to fit their content.

Resources