Im unable to switch values in a dropdown in cypress. The dropdown is not select type - dropdown

In my scenario i need to switch to the values available in the dropdown and verify the results based on the selection.I have 'In-Network' and 'Out-of-Network' values in the dropdown. By default one value will be shown and another one is hidden. This dropdown is not a select type. So when i try,
cy.get('#react-select-dropdown-value-value').select('Out-of-Network'); - Script fails and the error says, the element is not select type.
Then tried,
cy.get('#react-select-dropdown-value-value').eq(0).click(); -
it clicks the dropdown, and doesnt click on the value intended. i have tried click({multiple: true}). but didnt work. force:true, is not clicking either.
cy.get('#react-select-dropdown-value-value').contains(Out-of-Network').click(); - did not work, says the element is not found
cy.get('#dropdown-value')
.should('be.visible')
.eq(0)
.contains('Out-of-Network')
.click();
CypressError: Timed out retrying: expected '' to be 'visible'
This element '' is not visible because its content is being clipped by one of its parent elements, which has a CSS property of overflow: 'hidden', 'scroll' or 'auto'

The react-select-dropdown is a bit special indeed. What we do to select a value from a react-select-dropdown is the following:
cy.get('[id*="start-shift-floats"]').click()
cy.get('[id^="react-select-"]')
.contains('Out-of-Network')
.click()
What you should know about this:
cy.get('[id*="start-shift-floats"]') is the actual get() to open up the dropdown. So it will be named different in your application.
cy.get('[id^="react-select-"]') is the usual get() for the options in a react-select-dropdown. By checking it which contains 'Out-of-Network', we can let Cypress click that specific option.

Related

selenium python how to find and click element that change everytime

im trying to find an element with dinamic values , for example <span class="ms-Button-label label-175" id="id__177">Save</span> in inspect element, the id and class values tend to change for every refresh, how can i in this case find the element in selenium? i tried troguht xpath but seems doesnt work because can not find the path, i was thinking to find "Save" world torught always find by xpath but actually i dont know if im doing well : driver.find_element_by_xpath(//span(#.... but then? how can insert element if it changes everytime? thanks!
Something like this may work:
driver.find_element_by_xpath('//span[text()="Save"]')
But this will fail, if there is more than one button with text "Save" on the page.
In that case you may try to find some specific outer element (div, form, etc.) which does not change and contains the button. Then find the button inside of it.
With few requests with driver:
specific_div = driver.find_element_by_id("my_specific_div")
button = specific_div.find_element_by_tag_name("span") # e.g. there is only one span in that div
Or with more specific xpath:
button = driver.find_element_by_xpath('//div[#class="some-specific-class"]/span[text()="Save"]')
If needed, search for more nested elements before the button, so you can get more narrow search field.
More examples in the docs.

element can't seem to be located in webdriverio script

Currently trying to test out the responsiveness on webdriverio. I adjust the viewport of my screen and then try to search for a table that exists at the bottom of the page (need to scroll to get into view port). For some reason, it can't locate the element and the test case fails.
it('should resize the table when screen width is mobile', () => {
let mobileTable = $('.overview-table.mobile-table');
browser.setViewportSize({
width: 767,
height: 500
});
//browser.pause(1500);
mobileTable.waitForExist(10000);
console.log(mobileTable);
mobileTable.scroll();
browser.debug();
});
I'm not sure if I'm getting the element right in the above code. I set mobileTable = $('.overview-table.mobile-table') because it is a table element with those classes
<table class="overview-table mobile-table"> ... </table>
I get the following error:
An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
running firefox
Error: An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
at scroll() - index.js:312:3
The problem most likely is in your selector.
You can verify if your selector is correct by testing it into your browser javascript console.
In chrome it goes like this:
Right click the page
Inspect
Select the "console" tab within the dev tool panel
Then simply type $$('.overview-table.mobile-table')
If that's an empty array, then you know the selector is wrong.

selenium (phpunit) click on drop down link

I want be able click on link from drop down using selenium with phpunit. I don't have any idea how make it happens, can anyone show me example or relevant tutorial, post or anything that can help me figure out.
when I try click on the element without put mouse over the drop down I got this error:
Element is not currently visible and so may not be interact with command ....
Thanks.
EDIT:
when I said "drop down" I don't mean regular select. it more like popup
you can see the example here:
http://investing.com
look how they build the menu I want be able click on 'Technical' -> 'Fibonacci Calculator' for example.
Check this post out:
Selenium: How to select an option from a select menu?
You can find more info about this here
select(selectLocator, optionLocator)
Arguments:
selectLocator - an element locator identifying a drop-down menu
optionLocator - an option locator (a label by default)
Select an option from a drop-down using an option locator.
Option locators provide different ways of specifying options of an HTML Select element (e.g. for selecting a specific option, or for asserting that the selected option satisfies a specification). There are several forms of Select Option Locator.
label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
label=regexp:^[Oo]ther
value=valuePattern: matches options based on their values.
value=other
id=id: matches options based on their ids.
id=option1
index=index: matches an option based on its index (offset from zero).
index=2
If no option locator prefix is provided, the default behaviour is to match on label.
Credits go to Dave Hunt
What I use:
$search13 = $this->webDriver->findElement(WebDriverBy::id('id_of_dropdown_field'));
$search13->click(); // Clicking on the dropdownfield
$this->webDriver->getKeyboard()->pressKey('ARROW_DOWN'); // Will go down in your dropdown selection )
sleep(1);
$this->webDriver->getKeyboard()->pressKey('ENTER'); // Enter for submitting your selection
EDIT:
http://www.anitpatel.net/2012/02/25/selenium-webdriver-how-to-click-on-a-hidden-link-or-menu/
This one explains it in java but basically what he does is a mouse over/hover and wait.
Then he clicks on the element.
I'm not a java genius but it's an example how to work with it.
You can use the:
string mouseOver(string $locator)
This simulates a user hovering a mouse over the specified element.
http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/selenium.html
Check if the element is visible using the xpath of the required option value.
$this->isElementPresent($xpath);
$this->click($xpath);
If it is true, then click() method selects the specified option.

How to find whether button is disabled or not in Selenium IDE

I want to check whether button is disabled or not by selenium IDE But I couldn't.
I have tried below code but it doesn't work. is there any other way to find whether button is disabled...? <tr><td>assertElementPresent</td><td>
//button[contains(text(), 'Save')]</td><td>/td></tr>
In WebDriver. There is a method isEnabled which returns true if the element is enabled else it returns false.
driver.findElement(By.id("elementID")).isEnabled();
You can use VerifyNotEditable to check your Element,Button in this case..
A button can be disabled in many ways...so you will need to think about that but a simple solution would be the assertAttribute command, using the attribute disabled.
This will ensure the element has the disabled value set, which is a common way to disable elements, but not the only way.
3 years later...I am using Selenium IDE to test whether the DOM button has been disabled:
Command: assert element present
Target: xpath=//button[#disabled]
now, I have an id for button as well, so I included that in the square bracket to ensure I am "looking" at the right button.
Hopefully, this helps somebody.
I got the answer by following way. I am getting all the style classes by using "window.document.getElementById('requiredId').className" and searching for required disable style class by following expression.
|assertExpression | javascript{storedVars['classname'].search("disabled-style-cl‌​ass") == -1} | false |
instead of is_enable use get_property :
element = driver.find_element_by_name("element_name")
prop = element.get_property('disabled')
You can check the Element visibility by using the assertVisible command.
Code:
Command = assertVisible
Target = Locator Value
Returns true if the specified element is visible, false otherwise
Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present.

Not able to get tooltip text using Selenium WebDriver

I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.
I am using following code sequentially to get the tooltip text of all 5 elements:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
The issue is I get only the tooltip text of first element printed in console.
Is it because I need to refresh or reset the builder?
It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.
Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.
Console.WriteLine(Element1.GetAttribute("title"));
Console.WriteLine(Element2.GetAttribute("title"));
Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.
Console.WriteLine(InputElement1.GetAttribute("title"));
Console.WriteLine(ImageElement1.GetAttribute("alt"));
http://www.javascriptkit.com/howto/toolmsg.shtml
I think, it needs to release from element as:
builder.release(Element1).perform();
So, your code could be as below:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.release(Element1).perform();
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.release(Element2).perform();
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
builder.release(Element3).perform();
I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.