Selenium Webdriver issue with no Frame found - iframe

Can someone please help me figure out how to get Selenium Webdriver to find the frame after selecting Sign in??
https://www.guaranteedrate.com/agent/visitors
tap sign in
sendkeys to Username
#Test
public void fail() throws InterruptedException {
driver.findElement(By.linkText("Sign In")).click();
driver.switchTo().window("GB_window");
driver.switchTo().frame(0); driver.findElement(By.id("username")).sendKeys("testgr100#gmail.com");
}

Can you try this and tell me if it works? I suspect that what you are experiencing is a Firefox-only weirdness and a JavaScriptExecutor will get around it.
public void setEmailAddrOnFieldInSubFrame() {
driver.findElement( By.linkText("Sign In") ).click();
driver.switchTo().window("GB_window");
driver.switchTo().frame(0);
WebElement element = driver.findElement( By.id("username") );
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript( "arguments[0].value='testgr100#gmail.com';", element );
//cleanup frame position by switching back to previous window
driver.switchTo().defaultContent(); // always do this cleanup just in case
}

I think after clicking on Sign in you are taken to a frame, that is the registration form.
What you are trying is to Switch to a window first (GB_Window).
Try removing Switch to window call and just switch to frame and try your operations
After editing your code, use this
driver.findElement(By.linkText("Sign In")).click();
driver.switchTo().frame(0);
driver.findElement(By.id("username")).sendKeys("testgr100#gmail.com");
}

Try the below code. It worked for me. There are two frames before you can find Username Element. First frame is GB_frame and the second one doesn't have a any name given in the html source. So i have used index (frame(0)) for the second one.
#Test
public void fail() throws InterruptedException {
driver.findElement(By.linkText("Sign In")).click();
//switch to frames inside the webpage
driver.switchTo().frame("GB_frame"); //1st frame
driver.switchTo().frame(0); //2nd frame
driver.findElement(By.id("username")).sendKeys("testgr100#gmail.com");
}

Well if the application works on firefox then simply right click. In the context menu you will first find out if the element is under a frame or not by seeing an option This frame. Once you confirm this then inspect the element. Scroll top slowly in the firebug and you will find the iframe tag under which the element is present. In this manner you will get to know the name. If you want to know the count of all the iframes and their names then use
driver.findElements(By.tag("iframe")). This will return the list of webelements which have the tag and then you can iterate one by one and use getAttribute("name"). Note this will return the name only if the iframe actually has a name other wise will return empty.

Related

Prevent adding white space in VATNum

In TaxVatNumTable form, i need to eliminate white spaces in the field VATNum when a new record is inserted. Now, what i already did is to override the modifiedField method on the TaxVatNumTable:
public void modifiedField(FieldId _fieldId)
{
super(_fieldId);
switch (_fieldId)
{
case fieldNum(TaxVATNumTable, VATNum):
this.VATNum = strRem(this.VATNum," ");
break;
}
}
Works pretty well but is there another way to accomplish this? I am thinking at something like OnPreviewKeyDown event in WPF, check the pressed key and if space, do nothing. Is this possible?
The way you have done it is the best way to do it.
The TextChange method implies test for each keystroke, never do that in AX.

Qt QImageReader won't loop, uncontrollable

really quick problem here
I'm trying to use QImageReader to read the frames of a Gif, but when the animation finishes, it won't loop. I can't even control which frame is loaded, as using either the ImageReader's read() function to return a QImage OR using QPixmap::fromImageReader() both cause the QImageReader to automatically jump to the next frame. The problem is that they both use the same logic where if it is at the end of the animation, return only null instead of resetting.
Here is the way I'm attempting to work with Gifs: My class has a QTimer and a QImageReader. Upon TimeOut of the timer, I call my "nextFrame()" slot.
void GifPlayer::nextFrame()
{
if (img->currentImageNumber() == img->imageCount()-1)
{
img->jumpToImage(0);
}
else
img->jumpToNextImage();
this->lbl->setPixmap(QPixmap::fromImageReader(img));
}
I must be making some fundamental problem here - can someone please help me? I've even updated to the latest version of Qt, and it hasn't helped
QMovie sounds like a better fit for your use case, provided you can use that instead. The following gives the basic idea and will work with a GIF, looping automatically:
...
void MyWindow::init() {
movie = new QMovie("mymovie.gif");
if(!movie->isValid()) {
qFatal("Movie not valid");
}
movie->stop(); // Ensure stopped.
}
void::MyWindow nextFrameSlot() {
this->lbl->setPixmap(movie->currentPixmap());
this->movie->jumpToNextFrame();
}
...
This isn't something I've tried, but the QImageReader class has the following three methods:
int currentImageNumber () const
For image formats that support animation, this function returns the sequence number of the current frame.
int imageCount () const
For image formats that support animation, this function returns the total number of images in the animation.
bool jumpToImage ( int imageNumber )
For image formats that support animation, this function skips to the image whose sequence number is imageNumber.
It seems to me like it would be possible with the first two methods to determine when you've read the last frame of the animation, and then use jumpToImage to jump back to the first frame before the next read().

RequestCode changes along the way

I have a fragment within a fragment
both fragments load fine, except in one of the fragments i have a start camera intent with activity for result
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQ_TAKE_PHOTO);
}
now my REQ_TAKE_PHOTO is defined as follows :
public static final int REQ_TAKE_PHOTO=301;
however, in my onActivityResult the request code i get when returning from the camera intent is
131373 -> not the code i sent the request with
what could be changing the code along the way ?
note that when the inner fragment (the one that is incharge of taking the picture) is run separately, the code returns as 301 normally
to make the requestCode be what it was when i started the startActivityForResult
I need to do requestCode&0xffff
This is apparently a bug in the android support library
according to this: https://code.google.com/p/android/issues/detail?id=15394

How to Clear Static array in Flex action Script

I am using Flex Action Script.I am facing issue with static array. I have one static array used by two tabs.First time when I login the data is coming fine but if I am going to another tab and coming back to first tab then data from 2nd tab is appended into it and displayed in first.How to get rid of this problem?
//I'm assuming you have a var like this:
public static var sharedArray:Array;
//Then, assuming you're using a Spark TabBar, make sure you have a "change" listener defined for it, and make sure it includes the following code:
public function onTabChange(event:IndexChangeEvent):void {
sharedArray = [];
}

Selenium Webdriver and PageFactory initialize List<WebElement> elements

I have searched the Selenium Webdriver APi docs hosted on google code. Currently using the PageFactory to initlize my Page objects, but having issue initilizing a list of WebElement.
What I need is a way to initialize a list of elements, ideally a list of drop-down select boxes.
I have looked at the API references to #Findsby and #ByChained but still can not figure out the best way to initlize a list of dropdown select boxes. I COULD have a seperate WebElement for each one and grab the ID but I would like to initlize a list of List selects
Currently I use the following:
public class PageObject {
#FindBy(id="element_id")
private WebElement element;
public getElement() {
return element;
}
}
Is there some way I can use something similar to the following that I seek:
public class PageObject {
#FindBys(className="selectItmes")
private List<WebElement> selects;
public List<WebElement> getSelects() {
return selects;
}
}
Or must I use a single Web Element for each element? :(
Update
Anyone know how to use the PageFactory and initlize a List elements; using the FindsBy annotation. I can't find any way of doing this yet there are google issues on the selenium google docs site saying this has been fixed in the Java api bindings and in version 2.12 as it was mistaken disabled in 2.11.... I still can't initialize a list. =/
This feature has been recently added in Selenium 2.0. Check this issue. It is fixed now.
From the documents, you could do something like,
#FindAllBy(className="selectItmes")
List<WebElement> selects;
If you are interested in the code, check this out
Here is standard solution what I do in our test framework, until #FindAllBy doesn't work in Selenium library:
private List<WebElement> selects;
public List<WebElement> getSelects() {
selects = getDriver().findElements(By.xpath("..."));
return selects;
}
You can find the select options fairly easily all you have to do is use the Webdriver.Support dll reference. This gives you access to the SelectElement class. Here's a quick example:
IWebElement element = driver.FindElement(By.TagName("select"));
SelectElement select = new SelectElement(element);
int options = element.FindElements(By.TagName("option")).Count();
select.SelectByIndex(new Random().Next(1, options - 1));
The above code finds the select element, get's a count of the options in that select element and then chooses one at random.
The code may be slightly different because my code is written in C#
#FindBys(#FindBy(xpath="//span[#class='ng-binding']"))
private List<WebElement> AllData;
public List<WebElement> getAllData() {
return AllData;
}
I solve this problem like So:
#FindBy(id="element_id")
public List<WebElement> selects;
You now have a list of all the web elements with that ID.
Then, you just grab the element out of the list like you would any other PageFactory WebElement list.
I know this is an oldie, but lost a lot of time with similiar issue. At my end problem was that I never really initialized the list. So this did not worked:
#FindBy(css = .randomlocator)
private List<WebElement> list;
but this worked:
#FindBy(css = .randomlocator)
private List<WebElement> list= new ArrayList<>();
Maybe it will help someone.

Resources