how open url with click on one div in Watin automation - watin

how open url with click on one div in Watin automation
i am going to url by this code
browser.GoTo(address);
browser.WaitForComplete();
and click on a div like this
var main_tab1 = browser.Div(Find.ByText("main_tab"));
main_tab1.click();
i want when browser going to url the div be cliked
and no need to click ... and the automation will be faster

I am not sure if I have understood your question right. You are asking whether you need to navigate to page on click on Div using browser.Goto(address)? If so, try to navigate directly to the address. Capture the URL when u click on the div and send it to GOTO method.

i click on a button
var repbtn = browser.Button(Find.ById("btnReply"));
repbtn.Click();
and goto a page after click on btnReply
and in this page i have 4 tabs that i must click on one of theme
in this page i capture url with this code
string rep_url=browser.Url;
browser.Goto(rep_url);
and when i click on one of 4 tabs the url not changed that i captured its url
var main_tab = browser3.Div(Find.ByText("main"));
main_tab.Click();
the main_tab Div have onclick method , do i run this method even url loading .

Related

On button click, Read text from 'p' html tag & open in new window browser tab

I am new in cypress testing. On button click read 'p' html tag content text which is url & open url into different browser tab.
Cypress can't handle multiple browser tabs. If you want to test the hyperlink for the p element you could do two things:
1. Check what the URL is (and that is probably not the p element but an a href element. You could check that via:
cy.get('a')
.should('have.attr', 'href', 'URL_WHICH_IT_SHOULD_CONTAIN')
Click the element to see if the URL is correct:
cy.get('p')
.click()
cy.url()
.should('contain', 'URL_WHICH_IT_SHOULD_CONTAIN')

How to verify element displays in new window after clicking a link on the main window

I am using Cypress to click a link on the Homepage which opens the respective page in the new window. I am not able to identify any element on this page. I am doing this to verify that the click opens the correct page.
I saw the link: Access a new window - cypress.io which didn't help much to answer the problem.
Please suggest if there is some way to test this.
I have tried few things like:
cy.window().contains('.div.trItem')
cy.window().its('.trValue).should('eq','SomeHeading')
cy.url().should('include', '/theLink1.html/')
Expected:
- Clicking link open the correct page in new window
- Identify URL in new window includes some text
- Certain text displays on the new window
First of all, you can't access to another tab or window with Cypress. Consider to separate your test cases. For example, in one test you could check that a element contains href attribute with expected url and target attribute with _blank.
Like this:
it('contains valid a element', () => {
cy.visit('https://example.cypress.io/')
cy.contains('Cypress.io').should('have.attr', 'href', 'https://www.cypress.io').should('have.attr', 'target', '_blank')
})
And in second test check that your other page contains expected text.

iFrame tabbing within frame/pop-up window

As shown in the following example, I would like to restrict the tab key behavior to just this frame with links.
http://jsfiddle.net/zFXNM/
tabindex ="1"
I do NOT want the tab to go the URL other items in the browser.
For example, the "Compose Mail" in Gmail does this already. I observed 3 usages of "tabindex=-1" within the JS.
In pure JavaScript, I have figured out a solution for this issue. The idea is whenever the page is loaded we determine the first and last links, then we prevent the tab default action and jump to the first link from the last tab.
if (activeElement.id == lastHrefID) {
e.preventDefault();
document.getElementById(firstHrefID).focus();
}
A working solution is available at : https://jsfiddle.net/srirammac/95sv63s7/

Is there a way to print html source without having it displayed in a window or tab?

So I have this situation:
I perform an ajax post to a controller action that returns me some complete html source (i.e. if the result was viewed in a browser and you right-clicked and selected view source, all of that is what gets returned).
Now I want to be able to print that html source as if was being displayed in a browser (i.e. not the markup but what a user would actually see if it was being displayed in a browser).
This must be done without opening a new tab or window or popup window. Is it possible? And if so how?
Thanks
How about with a temporary, invisible iframe?
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.contentDocument.open();
iframe.contentDocument.write(html_source_here);
iframe.contentDocument.close();
iframe.contentWindow.print();
document.body.removeChild(iframe);
Yes, You can do it by creating a DIV and add the HTML by calling the innerHTML function.
document.getElementById('yourNewDIV').innerHTML = htmlReceived;

ajax page loading -Dojo

Hi I have a page with a navigation menu on the left and when any link
on this menu is clicked , an Ajax get call is sent to the server and
the right side gets updated with the new page.
How I am currently doing this is by creating 2 columns, the left col
contains the navigation link and the right col contans a div named the
content which has a dojotype of dojox.layout.ContentPane.Now when the
data is received from the server, I change its content like this
dijit.byId("thecontent").setContent=data
Now when I click on the navigation link , the right side gets
displayed properly(this page has dijits and also some scripts to
handle onclick events). But firebug returns an error saying
"Tried to register widget with id==thecontent but that id is already registered"
my main dojo include looks like this:-
<script type="text/javascript" src="http://o.aolcdn.com/dojo/1.5/dojo/dojo.xd.js"djConfig="parseOnLoad:false"></script>
I do a dojo.parser.parse() in the function dojo.addOnLoad like this:-
dojo.addOnLoad(function(){
dojo.require("dijit.form.Button");
dojo.require("dijit.form.Textarea");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dojox.layout.ContentPane");
dojo.require("dijit.Editor");
dojo.addOnLoad(function(){
dojo.parser.parse();
sendgetrequest();//this initiates the xhrget request
dojo.removeClass(dojo.byId("doc3"),"hiddendiv");
}
);
})
I am also unable to run any scripts in this new loaded page. No onclick event is working, just the dijit widgets are displayed...
The error means, as Ken already said, that you are creating a dijit with an id that already exists. My guess would be that you load the AJAX content in the right panel without destroying the old right panel first.
Try calling destroyRecursive on the main dijit container in the right panel before loading the new content. Also, if you do not need to set the id of the dijit, you just might drop the id (but that would leave a memory hole because the old dijits are not destroyed).

Resources