Here is the scenario:
I click a button and a popup comes and I want to test when I click on button, the popup should be visible
Sample code:
<button id='bt'>
<div id ='new_div' data-state = visible >
cy.get('#bt').click()
//after clicking this I need to test data-state of "new_div" is visible/not
cy.get('#new_div').should('have.data-state','visible') //something like this
You can do this:
cy.get('[data-state = visible]').should('be.exist')
It will basically check if this tag data-state = visible present or exist inside your DOM at the moment when the popup is visible.
But the best way, of course, is to grab selector from the opened popup!
Related
I am trying to click a button, which once clicked some text should appear. Selenium is not throwing any errors which means the buttons should have been clicked however the text is not appearing (it works manually).
<button class = "redButton one">
<img src = "images/name.png" class = redImage">
"Name"
</button>
I tried to click the button with the xpath: "//button[contains(text(), 'Name')]". I don't understand why the text is not appearing.
What is the expected text to be displayed after button click event? In order to help with this request, provide the HTML snippet of <button> before & after click event. Since this is working fine manually, did you try adding adequate wait time for the text to display?
I have to execute a div like this. When the user clicks on the card, it will be redirected to a different page, but when the user clicks on the button inside the card, it will be redirected to another page.
<v-ons-card
#click="goToPage1()"
>
<div>
// content
</div>
<div class="card-btn">
<v-ons-button
#click="gotopage2()"
>
View
</v-ons-button>
</div>
</v-ons-card>
In this implementation, when I click the button, it also triggers the card click event and then triggers the button click event. Is there any way I can prevent this?
Yes you can use Event Modifier for that. In your case you are searching for #click.stop.
So you can do as follow:
<v-ons-button #click.stop="gotopage2()">
on whom I am able to click, on clicking , nothing happens, i.e. the action is disabled. However, a tooltip gets displayed. The tooltip appears only when we focus on the button.
The html of the button is as follows:
<button type="button" style="color:#ffffff;" rel="rel-517347" data-toggle="popover" data-animation="true" data-placement="top" data-html="true" data-trigger="hover" data-content="<span class='text-center'>
<div>Ride can only be edited before </div><div>1 hour of pickup time.</div>
</span>" class="btn btn-default disbleBtn width_100" data-original-title="" title="">Edit Ride</button>
where Ride can only be edited before is the tooltip.
How can i verify the text of the tooltip as it keeps getting destroyed.
Note that isEnabled() function returns true here as i can click on the button, but no action takes place.
Is there any way I can verify the class of the button i.e btn btn-default disbleBtn width_100 ?
Is there any function or method for it?
I supposed you need to hover not click on the button. When hover tooltip is showing and than you click immediately and tooltip gone.
Do it manually with chrome devtools, open devtools-> sources tab, hover on the button and press F8 to pause then inspect tooltip element. After you get selector for tooltip try codes below:
new Actions(driver).moveToElement(buttonElement).perform();
String tooltipText = new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(toolTipLocator).getText();
//Verify
Or try this:
new Actions(driver).moveToElement(buttonElement).perform();
new WebDriverWait(driver, 10)
.until(ExpectedConditions.textToBePresentInElementLocated(toolTipLocator, textToVerify)
I'm testing with Selenium WebDriver, RSpec and Capybara.
I let the program successfully fill in some fields in a modal window. Now I want to click on a button that is at the bottom of this modal window. At the first glance, I cannot see this button, so Capybara needs to scroll down in the modal window.
The two relevant code snippets of the webpage:
<div class = “modal”> </div>
<button class=”btn …..”> TextOnButton ::after </button>
I tried:
within('.modal') do
find('.btn', text: ‘TextOnButton').scrollIntoView(true)
end
but received the error message.
Unable to find visible css ".btn" with text "TextOnButton"
I tried:
within('.modal’) do
page.execute_script 'window.scrollBy(0,100)'
end
but then he scrolls the main window but not the modal window.
Assuming your HTML snippet is incorrect and the button element is actually contained in the modal (as in your text description), then you can try something like
within('.modal') do
btn = find(:button, 'TextOnButton', visible: :all)
execute_script('arguments[0].scrollIntoView(true)', btn)
btn.click
end
This work:
execute_script('arguments[0].scrollIntoView(true)', element)
I understand you are already executing code on the modal, but just wondering have you used driver.switchTo().window(handle) to switch to that modal first?
Here is how my html looks like on the web page:
<form id ="invoice request">
<div id = "charges">
<div id = "charges">
<div id= "billing">
<a id = "modify" class="modify_link" href = "#"> Modify </a>
I am unable to load Web page by clicking on Modify charges link. Selenium test passes without actually loading webpage.
Here are my trails:
driver.findElement (By.id ("modify")).click ();
wait.until (ExpectedConditions.presenceOfElementLocated (By.id ("modify")).click ();
What's wrong in the code?
You're expected condition doesn't actually do anything there. You're HTML shows that the element is already present when you click, because it's what you clicked. That element will still be on the DOM. You need to find an element (on what I am assuming is an AJAX call) that is presented only after you have clicked the modify button to ensure that the click button you invoked did anything.