Need to hover on 5th rating and click on it - google-chrome

String exePath = "C:\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
WebDriver driver = new ChromeDriver();
// WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://wallethub.com/profile/test_insurance_company/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='footer_cta']/span/span")).click();
// To move to 4th star over the review
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath(".//*[#id='wh-body-inner']/div[2]/div[3]/div[1]/div"))).perform();
// action.moveToElement(driver.findElement(By.xpath(".//*[#id='wh-body-inner']/div[2]/div[3]/div[1]/div/a[4]")));
action.moveToElement(driver.findElement(By.xpath(".//*[#id='wh-body-inner']/div[2]/div[3]/div[1]/div/a[5]"))).perform();
action.click();[![enter image description here][1]][1]
tried the code but its not hovering neither it is clicking to go to next page

To do this, you will need to hover over the ratings section which then exposes a hidden portion of HTML that actually contains the ratings stars, etc. To find the initial element sometimes is hard because when you hover to right-click and Inspect, the element changes. What I usually do is find something nearby to Inspect and then hover the various elements until the right element is highlighted on the page. Another way to find it if it contains text is to search in the HTML for the contained text. Once you find the right element, you just need to hover it and then click on the correct star.
Since I'm assuming you will be using this code repeatedly, I write things like this into a function so that it's easy to reuse.
public void setRating(String stars)
{
// hover over ratings panel to expose ratings stars
new Actions(driver).moveToElement(driver.findElement(By.cssSelector("div.wh-rating-notes"))).perform();
// click specified star
driver.findElement(By.xpath("//div[#class='wh-rating-choices-holder']/a[.='" + stars + "']")).click();
}
and then you would call it like
setRating("5");
I have tested this code and it works.

Related

Unable to drag and drop an element under <li> to <td> using selenium Actions class methods

I'm trying to automate a use case where I should be able to drag an element which is enclosed by "ul>li" element to a target location, which is a "td" element under a table. My code is as below
WebElement source = driver.findElement(By.xpath("//div[#id='items']/ul/li[1]");
WebElement target = driver.findElement(By.xpath("//div[#id='cart']/table/tbody/tr[7]/td[3]");
Actions actions = new Actions(driver);
actions.clickAndHold(source)
.moveToElement(target)
.release(target)
.build()
.perform();
I have also tried pausing between each step, by adding
actions.moveToElement(source)
.pause(Duration.ofSeconds(2))
.clickAndHold(source)
.pause(Duration.ofSeconds(2))
.moveByOffset(1,0)
.moveToElement(target)
.moveByOffset(1, 0)
.pause(Duration.ofSeconds(2))
.release()
.pause(Duration.ofSeconds(2))
.build()
.perform();
While running in debug mode, I do see that clickAndHold is being performed, as I see the element highlighted. But the moment next action is being performed, I do not see the element dragged to the target nor released.
I'm not sure, if the issue is with the locator or the actions code.
I noticed the same behavior, if I used actions.dragAndDrop(source,target);
To simulate this, I tried to execute similar code against http://jqueryui.com/droppable/ and it is working fine. My code against this website is as below
driver.get("http://www.jqueryui.com/droppable/");
driver.manage().window().maximize();
driver.switchTo().frame(driver.findElement(By.className("demo-frame")));
WebElement drag = driver.findElement(By.xpath("//*[#id='draggable']"));
WebElement drop = driver.findElement(By.xpath("//*[#id='droppable']"));
Actions action = new Actions(driver);
//action.dragAndDrop(drag, drop).build().perform(); //This is working
action.clickAndHold(drag)
.moveToElement(drop)
.release(drop)
.build()
.perform(); // This is working
The only difference I noticed between this example and the former is, the position of the elements and how they are enclosed. In the former, the element to be dragged is under ul > li , and target location is a td element under a table.
Where as the example in jqueryui, is both are identified by id.
Also, I confirm that the xpaths used to identify the source and target in the former example are correct, as I can see them being highlighted when validated using Chrome developer tools.
Could you please suggest what can be done to fix this issue ?
Thanks
driver = new ChromeDriver();
driver.get("http://www.jqueryui.com/droppable/");
driver.manage().window().maximize();
driver.switchTo().frame(driver.findElement(By.className("demo-frame")));
//First, we capture the 1st element which we need to drag in variable "From."
WebElement From = driver.findElement(By.xpath("//*[#id='draggable']"));
//Second, we capture the 2nd element on which we need to drop the 1st element in variable "To".
WebElement To = driver.findElement(By.xpath("//*[#id='droppable']"));
//Third, we create object of Actions class as we use methods of Actions class.
Actions act=new Actions(driver);
act.dragAndDrop(From, To).build().perform();
For drag and drop element we use dragAndDrop method of Actions class and passes the parameters as the first element(Sourcelocator) "From" and the second element(Destinationlocator) "To". Below line will drag the 1st element and drop it on the 2nd element.
I faced like this issue, keep on trying different ways, this works for me:
Action dragAndDrop = builder.clickAndHold(src).moveToElement(trg).release(trg).build();
dragAndDrop.perform();
Thread.sleep(3000);
new Actions(oWebDriver).moveToElement(src).build().perform();
Thread.sleep(3000);
new Actions(oWebDriver).moveToElement(trg).click().build().perform();

RollOver and RollOut effect in buttons

I'm using the code bellow to change the color of button on rollover and rollout and clicked. I have following issues in this
1. The color did not changed when button is clicked.
2. Button wont work after once clicked.
pages.gotoAndStop("home");
// list of button instance names
var previousClicked:DisplayObject;
var buttonsss:Array = [home, menudown.about, menudown.portfolio, menudown.clients, menudown.pricing, menudown.contact];
for each ( var mc:MovieClip in buttonsss)
{
mc.buttonMode = true;
mc.mouseChildren = false;
mc.addEventListener(MouseEvent.MOUSE_UP, onClick);
mc.addEventListener(MouseEvent.ROLL_OVER, rolloverEffect);
mc.addEventListener(MouseEvent.ROLL_OUT, rolloutEffect);
}
function onClick(e:MouseEvent):void
{
pages.gotoAndStop(e.target.name);
e.currentTarget.mouseEnabled = false;
TweenLite.to(e.currentTarget,2,{tint:0x666666, ease:Strong.easeOut});
TweenLite.to(previousClicked,2,{tint:null , ease:Strong.easeOut});// set the previous clicked to null tint
previousClicked.addEventListener(MouseEvent.ROLL_OUT, rolloutEffect);// restore the Roll_Over effect
previousClicked = DisplayObject(e.target); // update the last clicked button
e.target.removeEventListener(MouseEvent.ROLL_OUT, rolloutEffect);
}
function rolloverEffect(e:MouseEvent):void{
TweenLite.to(e.currentTarget,2,{tint:0x666666, ease:Strong.easeOut});
}
function rolloutEffect(e:MouseEvent):void{
//should change tint to null just when its enabled, but its changing always (enabled or disabled)
TweenLite.to(e.currentTarget,2,{tint:null , ease:Strong.easeOut});
}
How I have always done this is with the built in buttons instead of doing it with code.
If you click window up in the top bar then click on components (near the bottom) it will bring up a little window then if you expand the user interface folder and drag and drop from the button item. Then with that button on the stage if you double click on it you will go into the edit symbol screen and it will have pictures of each state that the button and if you double click on the state you want then you can visually edit that version of the button.
Hope this helped.
Note: I first started with flash pro-cs5.5 and your tag says flash-cs5 I don't know for sure if that function is available or not in 5.
I am unfamiliar with Tweenlite, but I'm guessig that what it does in this case is simply change the color, am I right? If so, I'd suggest creating the color changes on your timeline and using framelabels combined with gotoAndStop to create the different effects. This should also solve your problem concerning the button not working after it has been clicked once.

Flipping through pages on a notebook (HTML5) using Selenium WebDriver (Java)

I want to flip through a notebook, without using any buttons or something like that, but actually clicking on the active element of the page or by dragging the page to get to the next one. The notebook is something similar to this one. I tried many different approaches but failed.
The code I am trying to get to work is:
WebElement page= driver.findElement(By.xpath("//*[#id='pages']/section[4]/div"));
Actions kkk = new Actions(driver);
Actions flip= kkk.moveToElement(page, 780, 200);
flip.click().build().perform();
I also tried the next approach :
flip.perform();
Thread.sleep(200); //to allow the mouse to hover and activate the page
flip.click().perform();
Nothing works, the mouse hovers over the neccesary place and if I try to click in the same place, it just resets and the page rolls back flat.
Also, is there any way finding the neccesarry place (the active spot of the element) without using Offset (coordinates), I can't think of any other way.
This seems more on the lines of drag and drop.
Try doing something like this
WebElement draggable = browser.findElement(By.xpath("//*[#id='pages']/section[4]/div"));
new Actions(browser).dragAndDropBy(draggable, 200, 10).build().perform();
Based on
org.openqa.selenium.interactions.Actions.dragAndDropBy(WebElement source, int xOffset, int yOffset)
UPDATE
or this way
WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));
(new Actions(driver)).dragAndDrop(element, target).perform();
UPDATE 2
Or this way
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(someElement)
.moveToElement(otherElement)
.release(otherElement)
.build();
dragAndDrop.perform();

Unable to refresh JTabbedPane

I am using JTabbedPane with JPanel to display JTable on one tab and text, dropdown and jbutton on other tab.
First time it is working fine but if i minimize or switch screen to other application and come back to my application it display data correct but with a serious problem with tab change in JTabbedPane. Now tab screen goes to blue and don't display the data.(I hope data is there but it is not repainting or refreshing complete window).
Now with blue screen i do the same procedure and change tab in JTabbedPane it shows correct data.
I used repaint but it doesn't work.
Help needed to refresh window or tab correctly.
It may problem of Browser you are using jdic.dll. Try using any other browser to reload your tabbed pane.
I guess this "issue" is an evergreen. I assume, that most people stumble over this issue possibly when implementing JTabbedPane changes (removing and adding of tabs) in the wrong event-method:
For example, if you want to remove a tab and add a new one in the tabbed pane based on a selection in a JComboBox, you have to put your logic into an 'itemStateChanged'-event of the ItemListener added to this combo-box. If you put your tab-change-logic e.g. into an propertyChangeEvent (PropertyChangeListener), you are doing it all wrong and the timing is always messed up for repainting/refreshing tabbed pane UI elements!
If you use the right event-method, you don't even have to call setVisible, revalidate nor repaint. It will all work out perfectly.
Here's a simple example:
JComboBox<String> c_editor = new javax.swing.JComboBox<String>();
c_editor.setModel(new javax.swing.DefaultComboBoxModel<>(
new String[] { "CSV", "EXCEL", "HTML" }
));
c_editor.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
c_editorItemStateChanged(evt);
}
});
...
protected void c_editorItemStateChanged(ItemEvent evt) {
// get the value selected in the combo box
final String val = c_editor.getSelectedItem().toString();
if (tabbed_pane.getTabCount() > 1) {
// remove the panel which is at position 1
tabbed_pane.removeTabAt(1);
}
if (val.equals("CSV")) {
// add the panel for viewing CSV files
tabbed_pane.addTab("CSV Editor", p_csv);
} else if (val.equals("EXCEL")) {
// add the panel for viewing Excel files
tabbed_pane.addTab("Excel Editor", p_excel);
} else if (val.equals("HTML")) {
// add the panel for viewing HTML files
tabbed_pane.addTab("HTML Editor", p_html);
}
}
That's all, nothing else necessary - the UI will update itself. PS: This issue has nothing to do with browsers as suggested by the 'favoured' answer in this thread, it's all about Java Swing GUI's.

ColorPicker not editable in Form -> FormItem

Please note the remark mentioned WORKAROUND at the end of this question.
Based on a Dictionary based specification, one of my classes creates a Form programmatically.
Adding TextInput or DatePicker to FormItemss works as expected.
Unfortunately, the following code just creates a colored rectangle, not the actual picker:
ti = new ColorPicker();
ColorPicker( ti ).selectedColor = TAColor( _spec[ key ].value ).color;
and later on
formItem.addElement( ti );
The Form is embedded in a TitleWindow component presented using
PopUpManager.addPopUp(...);
When added to TitleWindow, it shows up correctly, within Form->FormItem not:
I can't image, why the picker doesn't appear. Do you?
WORKAROUND:
If I wrap the ColorPicker inside a Group things work:
ti = new Group();
Group( ti ).addElement( new ColorPicker() );
In this case, the ColorPicker appears as editable.
Still, I'd be too happy to learn what the problem with my initial solution. Bug?
A DateField (which extends ComboBase like ColorPicker) behaves properly in a spark Form. But in the ColorPicker, the mouse down handler of the button never gets called. I think that maybe the skin part that handles the mouse clicks (it must be a button) is not properly dimensionned, and the result is it is not shown. I've come to this conclusion because within an mx Form, the ColorPicker doesn't display as it does when it is added to the regular displaylist...
Hope this helps...
In the code you've provided, you never add the colorPicker as a child to any parent container; as such it will never show up anywhere.
You probably need to do something like:
formItem.addChild(ti );
[or for a Spark formItem]:
formItem.addElement(ti );
I'm confused as to why you're seeing a rectangle.