Rad Menu and Div Issue - watir

one more problem... i have an application which have a rad menu telerik menu... and it is placed in a DIV as shown below.
e.g.
DIV class = RadMenu RadMenu_Hay id = ctl00_RadMenu UL class = rmHorizontal rmRootGroup L1 class = rmItem rmFirst Aclass = rmlink rmfirst Span class = rmtext #text...
i just want to know, how i use the div in watir to select menu and submenu both...any help in this regard will highly be appreciated...on internet i didnt find any specific example .. so help me out..
div class= RadMenu RadMenu_hay id='ctl00_RadMenu'
ul class rmHorizontal rmRootGroup
lI class = rmItem rmFirst
A class=rmLinkrmFocused
SPAN class = rmtext

I'd try this from IRB to see if it makes the menu open
browser.div(:id, 'ctl00_RadMenu').fire_event 'onmouseover'
if it does then you should then be able to do click on the appropriate link (most likely selecting by the text in the link.) You will also likely have to put a sleep of a second or so after the mouseover to give the client side code time to render the menu and get the objects inside it into a state where they can be seen and clicked.
Without seeing actual full real HTML I can't be sure. And without access to a site actually running that control there's no way for us to test it to be sure..

Related

How to close popover/popup by <a> element using Selenium

I'm working on a webscraper for https://www.grailed.com/designers/jordan-brand/hi-top-sneakers. When the page has opened a popup for login comes up. Searching through the web design I can locate the X element to close the browser like so: temp = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CLASS_NAME, 'close'))). If I go more into this there is an and element. I have tried using .click() on the element (with class 'close'), as well as the SVG and path elements. None of these close the box, and there is no button or other element of this kind for the X. What can I do to close this popover? I'm not sure if I need to find a button-ish element to click, but I can't find one like that. I've looked at a couple of questions and articles (https://stackoverflow.com/questions/61923909/trying-to-close-popover-python-selenium-glassdoor, https://sqa.stackexchange.com/questions/5310/how-to-close-pop-up-window-in-selenium-webdriver, https://saucelabs.com/resources/articles/the-selenium-click-command) but can't find a solution.
You can do double click with actions for resolving this problem
WebDriverWait(driver, 20).until(ec.visibility_of_element_located((By.XPATH,
'//a[#class = 'close']/*[name()='svg']')))
close = driver.find_element_by_xpath("//a[#class = 'close']/*[name()='svg']")
actionChains = ActionChains(driver)
actionChains.double_click(close).perform()
And the Java code for this:
new WebDriverWait(driver, 20)
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#class = 'close']/*[name()='svg']")));
WebElement close = driver.findElement(By.xpath("//a[#class = 'close']/*[name()='svg']"));
Actions action = new Actions(driver);
action.doubleClick(close).build().perform();
I actually just ran into the same issue myself. The above solution didn't work for me, so I'll post what I did here:
Essentially, I clicked by the coordinates instead of by trying to find the button element.
Note: some webpages don't display the popup until you try to click something else, so I had to first attempt to click another element. If you need to do that, make sure to wait a second or so for the popup to load.
Then, you can do the rest via ActionChain:
elem = driver.find_element_by_class_name("CLASSNAME")
ac = ActionChains(driver)
ac.move_to_element(elem).click().perform()
You'll want to encase this in a try-except block for extra safety.
Credit to Dirk Bergstrom for providing part of the solution here: Clicking at coordinates without identifying element

Scrolling down with Python Selenium on part of the web page

So I have a web page where a part of the page is a user list. A user can scroll down this list, but scrolling only works if the mouse pointer is located above this list. Keys like page down or end do not work.
I can locate the element using Selenium and Xpath without any issue, but I don't know how to perform the scrolling in selenium as it only works when the focus is on that specific web element.
I've tried sending keys like page down and end or code like
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Anybody got any ideas?
Because you mentioned you can locate the element, you could try scrolling to the specific element, instead of using document.body.scrollHeight as your scroll target.
element = driver.find_element(someLocatorHere)
driver.execute_script("arguments[0].scrollIntoView(true);", element)
Hope this helps a bit.
Scrolling can be achieved in two different ways.
Javascript
elementId = driver.find_element_by_id("elementId")
driver.execute_script("arguments[0].scrollIntoView();", elementId)
Action class
actions = ActionChains(driver)
actions.move_to_element(elementId).perform()

How do I select items from a drop down box in selenium using python

I'm attempting to iterate through a dropdown list for webscraping and I've noticed that my code isn't working out
dropdown = browser.find_element_by_XPATH('//*[#id="department-dropdown"]')
select = Select(dropdown)
select.select_by_value("Accounting")
ERROR MESSAGE I RECIEVE
Traceback (most recent call last):
File "C:\Users\David\eclipse-workspace\Web_Scrap\setup.py", line 31, in <module>
dropdown = browser.find_element_by_XPATH('//*[#id="mainContent"]/div[1]/div/div[3]/div/div/span')
AttributeError: 'WebDriver' object has no attribute 'find_element_by_XPATH'
For now I was attempting to select atleast the first value, but it just isn't working out
The picture provided has the "inspect element" of the dropdown box i'm attempting to cycle through
This seems a bit confusing that the dropdown box element isn't a part of the actual list, can someone give me an idea of what is actually going on here? and if I'm looking at this incorrectly.
And if anyone has any recommendations on what I can do to achieve my goal
Your drop down box is a css drop down, not a native drop down which implement purely by <select> and <option> tag.
the options of the drop down comes from li inside the <ul class="typeahead typeahead-long dropdown-menu", and they are attached to the page only after you click the down arrow at right side.
The reason there is a <select> with many <option> is the above li's attribute: data-value created upon these <option>. You can think of these <option> are the data source for li. So the <select> not visible on page, act like a data base behind frontend to supply data, thus the <select> style set to display: none which means not visible on page.
To act as a user behavior, you should find and select option from li inside ul after click it to expand all li. Rather than select option from invisible <select> or change select display css value to make it visible then select option from it.
// click down arrow to expand all options
driver.find_element_by_css_selector(
".department-combobox .input-group > span").click();
// search all options
options = driver.find_elements_by_css_selector(
".department-combobox .input-group > ul > li")
// print all option text
for(opt in options):
println opt.text
// select specific option by text
target = 'Anthropology'
driver.find_element_by_css_selector(
".department-combobox .input-group > ul")
.find_element_by_xpath("./li[.="+target+"]")
.click();

How to make parent menu active when the child menu was active in menu block using drupal 7?

I have created menu and its child links like
About
contact us
portfolio
our location
I have used menu block to display sub menu only when about in click and display sub menus in another layer.
Now my requirement is when i click on any sub menu in parent menu then the parent menu should be active. To achieve this task i searched a lot off and found menu position module for this purpose. I have configured and specify page path in Restricted to certain pages, but now it is now working. What i have mistake or any other solution for this problem. Please let me know the right solution.
<?php
$block = module_invoke('menu_block', 'block_view', '1');
print render($block['content']);
?>
I am adding this code below the topbar menu. but inside the menubar wrapper.
If my understanding clear then you will need this menu - Menu Position https://www.drupal.org/project/menu_position
This module allows for the creation of rules that will dynamically add the current page into the menu system at the requested spots.
If you dont want to use this module then you will need to append menu-id in the menu link's li and then through jquery / js will need to add certain classes to parent menu items.
Actually there is no requirement to use any module for this situation. What i have done to achieve it. I just modified template.php of zurb foundation theme. i have copied the code(foreach loop code) from here and added to the template.php file as mentioned in the page and added the css like below:
#main-menu li.active-trail a,
#main-menu li a.active, #main-menu li a:hover {
background:#fec325;
/* IE6-9 */
}
and that's it. i have achieve what i want. I hope anybody who is looking same kind of problem can find this solution useful for this kind of requirement.

Collapsible accordion not showing content when initialized collapsed

I'm using twitter bootstrap with JSF-2.2.4 and Spring 3.2.4 Framework. I've built a collapsible accordion based on the following tutorial: http://getbootstrap.com/javascript/#collapse
The code seems to work fine, but only if I start with opened accordions, meaning that I add the 'in' class to the div which inherits the content which is supposed to be collapsed. If I remove the 'in' class the accordion is opened by clicking the appropriate link, but the content is no displayed.
Content is plot created with plotfaces.
Any ideas?
Edit: I just tried filling the box with an image. This seems to work. Maybe this helps narrowing down the problem.
I don't know how this plotfaces work, but i expect your problem similair to fullcalendar not visible until button is clicked or window resized?
Try to set .collapse {display;block; visibilty:hidden;} instead of display none. If this don't helps try to focus on the height of the element. The plugin change the height from 0 to auto but on initial load the height is not set.

Resources