RSelenium: Uncollapse a Panel - rselenium

I am attempting to use RSelenium to check a box that is hidden from view due to the collapse panel.
<div data-ddm-collapsible-panel="Additional details" class="dfa-collapsiblepanel">
<fieldset role="region" aria-labelledby="panel1">
<legend id="panel1" role="heading">
<span>
<a href="#">
<span class="ddm-icon ddm-icon-collapsed"></span>
Additional details
</a>
</span>
</legend>
</fieldset>
</div>
I have tried a few different options but ran into the error of either the element not being found, or not visible. Some of my attempts:
expand_button <- remDr$findElement(using = 'class name', "dfa-collapsiblepanel")
Result: Unable to locate element
expand_button <- remDr$findElement(using = 'id', "panel1")
Result: Unable to locate element
I'm not familiar at all with xpath, but i attempted to modify the code found from searching online and got this:
expand_button<- remDr$findElement(using = "xpath", "//div[contains(#data-ddm-collapsible-panel, 'Additional')]")
Error: No such element.

Related

React Testing Library - can't find anchor element by role

I have the following code:
<div className="button">
<a href={SOME_URL}>
...
...
</a>
</div>
And in my test, if i try to do:
const link = screen.getByRole('link');
I'm getting the following error:
TestingLibraryElementError: Unable to find an accessible element with the role "link"
Running screen.debug(), i'm getting the following:
<div
class="button"
>
<a>
So how come it can't find it?
The a[href] has a default role of link...
source
You'll need to add an href to the <a>.

How to find element in selenium python using class in div with different selection

I have tried
driver.find_element_by_xpath( "//div[#class='pepDayScroller_dayNum']").click()
for below elements but it did not work. Please help.
Try to located second element with a number of 2
<div class="pepDayScroller_dayNum">1</div>
<div class="pepDayScroller_dayNum">2</div>
<div class="pepDayScroller_dayNum">3</div>
here is addition information
<div class="pepDayScroller_dayWrapper">
<a href="#" class="pepDayScroller_day pepDayScroller_day--selected" data-index="0">
<div class="accessibleText accessibleSelectedMark" aria-hidden="false">Selected</div>
<div class="pepDayScroller_dayNum">1</div>
<div class="pepDayScroller_startingFrom"><div
class="pepDayScroller_startingFromLabel">Prices vary by date.</div>
</div>
</a>
</div>
<div class="pepDayScroller_dayWrapper"><div class="accessibleText accessibleSelectedMark" aria-hidden="false">Selected</div><div class="pepDayScroller_dayNum">1</div><div class="pepDayScroller_startingFrom"><div class="pepDayScroller_startingFromLabel">Prices vary by date.</div></div></div>
once I am able to click on this button, it will scroll down and ask me to select either it is peak or value. codes are below
<a href="#" class="pepTieredCalendar_dateBox tappable pepTieredCalendar_dateBox--32 pepTieredCalendar_dateBox--value" tabindex="0" role="button" data-tier="value" data-date="2018-09-27" aria-label="2018-09-27, 87.30 USD">
<span class="pepTieredCalendar_dateBoxText">27</span>
</a>
how do I find these elements.thanks
The class which you're trying to refer matches many elements at once. You could try to find by matching text like:
driver.find_element_by_xpath("//*[contains(text(), '2')]")
or by matching all elements and selecting the one that you need:
all_elements = driver.find_elements_by_class_name("pepDayScroller_dayNum")
two_element = None
for el in all_elements:
if el.text == "2":
two_element = el
break
Let me know if that helps.

make typeahead search not found non clickable

I have following markup for type ahead which works fine, now the problem is I want to disabled click when no match is found basically make it non s selectable.
<a tabindex="-1" ng-if = " 'no results found' == match.model.formatted" ng-disabled>
<span> No Results Found</span>
</a>

How to select element from options populated

I need to write a script with Selenium-Webdriver. I am stuck in a situation where I need to enter text (e.g : "tt") in the textbox and a list gets populated (hidden values). We need to select an option from the populated list. (Like we do in "Google" search).
<div class="select2-search">
<input type="text" autocomplete="off" class="select2-input tabindex="-1" style>
</div>
<ul class="select2-results">
<li class="select2-results-dept-0 select2-result select2-result-selectable select2-new">
<div class="select2-result-label">
<span class="select2-match">et</span>
</div>
</li>
<li class="select2-results-dept-0 select2-result select2-result-selectable select2-highlighted">
<div class="select2-result-label">"Secr"
<span class="select2-match">et</span>"ary"
</div>
</li>
<ul>
So i'll write a little code to help you.
I'm using www.google.com as exemple.
WebElement inputElement = driver.findElement(By.id("gbqfq")); // get the input
inputElement.sendKeys("zyzz"); // you want to search him on internet ;)
// get all suggestions in a list
List<WebElement> suggestionList = driver.findElements(By.CssSelector(".gsq_a table tbody tr td:first-of-type span"));
To select an option you have 2 choices, first :
// you get a random option and click on it
suggestionList.get(1).click();
or
// you only want to click on the link that contains that.
for(WebElement elem: suggestionList)
{
String text = elem.getText();
if(text.equals("zyzz motivation"))
elem.click();
}

Cannot find the nth element on the page using nth-child and WebDriver

I have a form that has 4 calendar Widgets. The html source is the same for all the widgets.
<div class="grid_12">
<td class="wikicell">
<div class="Item">
<div class="Value">
<input type="hidden" id="Submit_Date$_type" value="Date,99/99/9999">
<input id="Submit_Date" size="40" value="" type="text">
<a href="javascript:" class="Calendar">
<img src="transparent.gif" class="Placeholder" tabindex="-1" align="absmiddle">
</a>
</div>
</div>
</td>
I am able to locate the first calendar using the following code:
driver.findElement(By.cssSelector("div.grid_12 img.Placeholder"), 15).click();
But when I try to located the 2nd, 3rd and 4th calendars using nth-child(2)/(3) or (4) I get an "Unable to locate element: {"method":"css selector","selector":"div.grid_12 img.Placeholder:nth-child(2)"}
I also tried with "a.Calendar", "div.grid_12 img" work too for the first calendar. These 3 selectors can successfully click and open the first calendar widget when used with "nth-child(1)" but not for the next 3.
I used Thread.sleep(3000) after the first calendar is closed but I end up getting the same error.
I used findElements() method to get all the calendar widgets and double check using size() to check if the WebDriver is locating all calendar elements. The result is 4 as expected.
Am I not using 'nth-child' correctly?
I first located the form/table that has these calendar icons and called findElement() on this element as a reference to find the respective calendars. Here's the solution -
WebElement form = uiHelper.waitForElementPresent(By.cssSelector("table.left tbody"), 15);
//Enter time
form.findElement(By.cssSelector("tr:nth-child(3) td:nth-child(2) img")).click();
form.findElement(By.cssSelector("tr:nth-child(4) td:nth-child(2) img")).click();

Resources