Couple Things With Selenium - c#

I've been doing some work with Selenium and Fiverr.com and I've run into some issues I was hoping to get some help on. I'm trying to create a new gig, and I've managed to do everything but a few things still are stumping me. One thing is the picture uploading.
• You have a button that you click a file input type () that brings up a Windows dialog, my plan thus far to use SendKeys.SendWait has worked, except for the part where you push "Open" on the Windows dialog to submit the picture. I've tried using SendKeys.SendWait("{ENTER}") to click it but that hasn't worked for me so far, so any ideas on that? I can't think of any other way to do it unless P/Invoke has something to handle Windows Dialog boxes?
•I'm also trying to enter text into the 'Description' box, and haven't been able to do that yet. I have tried to get it by class name, but it tells me that it can't access the class because it is hidden, have also tried to do it through Javascript (IJavaScriptExecutor) like so:
IWebElement detailFrame = firefoxDriver.FindElement(By.XPath("/html/body"));
var executor = firefoxDriver as IJavaScriptExecutor;
executor.ExecuteScript("arguments[0].innerHTML = 'hiiiiiiii'", detailFrame);
It's odd because they're using body for the text field like so:
<body marginwidth="0" marginheight="0" spellcheck="true" class="wysihtml5-editor" contenteditable="true" style="color: rgb(119, 119, 119); cursor: auto; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; letter-spacing: normal; text-align: start; text-decoration: none; text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word; word-spacing: 0px; overflow: auto; background-color: rgb(255, 255, 255);">TEXT HERE<span id="_wysihtml5-undo" class="_wysihtml5-temp"></span></body>
I think they're using two different 'bodys' though, but the XPath just shows that it's /html/body. How would I set the text for something like this?
Thank you guys for your help, been at this for the past two hours.

Selenium has mechanism for handling window. You can use driver.SwitchTo().Window(""); to set focus on newly opened window and perform additional action on it. However, keep that in mind to go back to parent window you may need to use default content again. See here for other window handling techniques.
First of all, selenium doesn't recognize hidden element. If you know for sure the element is not hidden then I might say taht the selector you are using probably not correct. If I understand the html you provided clearly and the element is visible then I suggest you use xpath for that element. //*[#id='_wysihtml5-undo']//.. can be helpful one for you

Related

How to recreate the opera gx button in ASP.NET Core

I wish to make buttons just like the navigation ones in opera gx new tab or firefox new tab in asp.net for my web site
background-origin: content-box;
background-position: 50%;
background-repeat: no-repeat;
background-size: cover;
I tried something like this but I think is much deeper than that...
your css codes have no relationship with the color ,and i'm not sure which color you do want,but I could give you some suggetions to get the color you want .
You could copy the img to the default Paint App of windows and get the RGB color:
You could adjust the value until you got the value you want
I tried as below:
<style>    
input{        
width: 230px;        
height: 80px;        
background-origin: content-box ;        
background-position: 50% ;        
background-repeat: no-repeat ;        
background-size: cover ;        
background-color:rgb(28,23,38);        
border-color:rgb(250,30,78);        
border-style:solid;                
color:rgb(250,30,78);        
font-size:40px;          
}
</style>
<input type="button" value="Click" id="but"/>
the button:

How to combine multiple CSS declarations to shorthand

I'm using AngleSharp to parse some CSS files, compare their structure and build an output file out of them. The tool makes all declarations explicit, i.e. if the source rule is:
.recent-work-wrap .overlay {
padding: 15px;
}
I get following output from AngleSharp:
.recent-work-wrap .overlay {
padding-top: 15px;
padding-right: 15px;
padding-bottom: 15px;
padding-left: 15px;
}
That is good for comparing rules and detect changes, but the question is, how can this rule be combined to a shorthand like above?
So for another example, how to get from this:
.sample-rule {
margin-right: auto;
margin-left: auto;
margin-top: 30px;
margin-bottom: 30px;
}
to this
.sample-rule {
margin: 30px auto;
}
The situation gets worse with CSS3 declarations, because they can really have a lot of parameters... I checked some CSS minifier/uglifier tools, but they mostly use RegEx to remove whitespace and smaller optimizations.
Is there a known way/tool/library to write optimal shorthands out of multiple declarations?
How do you get this output? Have you tried looking at the shorthand declarations (e.g., Margin) of the Style property?
Internally, AngleSharp only uses longhand declarations, thus the output is as verbose as it could be. However, AngleSharp knows most shorthands and should be able to recombine these longhands into their shorthand form.
I don't know if that helps you already. If not then please post some code (a MWE) and I'll try refine this answer.

Selenium Element Cannot Be Scrolled Into View: (34). Using NUnit, C#

Getting the error from the title when attempting to click on an <a> tag in a regression test script. I've researched the issue here: Selenium::WebDriver::Error::MoveTargetOutOfBoundsError: Element cannot be scrolled into view:[object HTMLSpanElement] and here as well: https://groups.google.com/forum/#!msg/webdriver/R2jwSWrIK44/RaCLRPlKIWEJ but I don't understand the root cause of the issue.
I've tried using By.jQuery, By.Id, By.Css, By.Xpath, as well as selecting by index and always get the same error. Here's the relevant code:
HTML:
<div id="divTabs">
<a id="tabECheck" target="#divECheck">eCheck</a>
<a id="tabAceComments" target="#divAceComments">Ace Comments</a>
<a id="tabReviewComments" target="#divReviewComments">Review Comments</a>
<a id="tabReviewHistory" target="#divReviewHistory">Review History</a>
</div>
CSS:
#divTabs{
writing-mode: tb-rl;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
position: absolute;
width: 27px;
padding: 0px;
height: auto;
display: table-row;
margin-bottom: 10px;
}
#divTabs a
{
border: 1px solid #CCC;
padding: 3px;
white-space: nowrap;
cursor: pointer;
color: #3966BF;
display: table-cell;
background-color: #FFF;
}
C#:
element = driver.FindElement(By.Id("tabReviewComments"));
element.Click();
As you can see, I'm trying to click on the 3rd <a> tag with the id of "tabReviewComments." However, if I have the script click on the first <a> tag with the id of "tabECheck", it works in the sense that I don't get the "can't scroll element into view" error, the element is clicked, and the script moves on past that line. Sadly, I need to click on that third <a> tag. Any ideas short of moving the <a id="tabReviewComments" target="#divReviewComments">Review Comments</a> to the top?
Thanks!
Its likely that the element is actually un-clickable as far as the browser goes, this may be because
Its position is off-screen (negative space)
Its behind another element (like modal overlay or something)
It has 0 size (sometimes css can be funny, browser maybe calculating size differetnlty to what your seeing)
A UI bug in your system whereby the element isn't visible for another reason

How to wrap content of H1 tag

I am unable to explain my question. But if anyone understood what I want please do edit.
I have following code
<table style="width:100%">
<tr style="border-style: none solid solid solid; border-width: thin; border-color: #C0C0C0; background-color: #FFFFFF">
<td class="style4" width="100%"
style="border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #C0C0C0"
align="left">
<h1 style="font-style: normal; font-weight: normal;">
<%=t.getTitle() %>
</h1>
Whenever t.getTitle() returns a larger string that is in one line, my heading goes out of the page (overflow). I want to wrap the content of h1 into td having it.
Like stackoverflow.com uses for its question titles.
Quite seldom, text overflows text-boxes. In such cases, one can force the browser to change wrapping. web designer wall explains it here:
.break-word {
word-wrap: break-word;
}
Changes rendering behavior like this:
Additionally, while maybe not helpful in the current situation, one may hide any overflow using CSS:
style="overflow:hidden;"
PS: Actually, I wonder, if word-wrap is the root cause your problem.
1000 words will be wrapped.
1 word with 1000 character won't be wrapped.
Try:
word-wrap:break-word;

How can I expand CSS shorthand properties programmatically?

Is there a .Net CSS parser that will allow me to parse css shorthand properties into their longhand form?
For example I'd like to take the following:
#somediv{
margin: 10px;
padding: 10px 20px;
border:5px solid #FFF;
}
And translate it to:
#somediv{
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 10px;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
border-width: 5px;
border-style: solid;
border-color: #FFF;
}
Here is a pretty good list of all the different properties I'd need to handle in this manner: http://www.dustindiaz.com/css-shorthand/
Ideally I'd like something in .Net but if there's something in another language that's open source I can probably adapt it.
Update
Without getting into too much detail as to exactly what I'm trying to do here is the basic premise:
I need to programmaticly take multiple CSS docs and merge them to create one definitive set of CSS.
So if doc 1 has :
p { padding: 10px;}
And then I add on doc 2:
p { padding-left:20px;}
The resulting CSS should be:
p { padding-top: 10px; padding-right:10px; padding-bottom:10px; padding-left:20px;}
Because the later added doc overwrites the single property. To do this accurately I would need to take every CSS and break down every property to it's lowest element first.
For regular CSS parsing I've found this to be the easiest to use:
http://www.codeproject.com/KB/recipes/CSSParser.aspx
For breaking down the shorthand properties into their longhand form I've found two that can do it:
In .Net : http://www.modeltext.com/css/index.aspx
In JavaScript: http://www.glazman.org/JSCSSP/
The most simplest approach would is to make use of .NET's WebBrowserControl along with MsHTML(IE Renderer) and this is most reliable approach too !
//Create the instance of new webbrowser control.
WebBrowser browser = new WebBrowser();
//Navigate to the specified URL.
browser.Navigate(#"test.html");
//Wait until the webpage gets loaded completely.
while (browser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
foreach (object divElement in
(browser.Document.GetElementsByTagName("div")))
{
IHTMLCurrentStyle currentStyle = ((divElement as HtmlElement)
.DomElement as IHTMLElement2).currentStyle;
Console.WriteLine(currentStyle.marginLeft);
Console.WriteLine(currentStyle.marginRight);
}
Note:
In order to get this code working you need to add reference to Microsoft.MSHTML.dll which can be found on the following location.
c:{Program Files}\microsoft.net\Primary Interop Assemblies\
Could you give a little more detail on why you want to do this?
And are you looking for it to do correct parsing with things like:
padding:10px 15px;
into
padding-top:10px;
padding-right:15px;
padding-bottom:10px;
padding-left:15px;

Categories

Resources