I am trying to learn selenium by automating amazon.in
I would like to click on a moving image in an e-spot. It seems there is no class or id. Then how can i proceed?
WebDriver driver= new FirefoxDriver();
#Test
public void test() {
driver.get("http://amazon.in");
driver.manage().window().maximize();
WebElement menu = driver.findElement(By.xpath("//li[#id='nav_cat_2']"));
Actions builder = new Actions(driver);
builder.moveToElement(menu).build().perform();
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[#class='nav_a nav_item' and .=\"All Books\"]")));
WebElement menuOption = driver.findElement(By.xpath("//a[#class='nav_a nav_item' and .=\"All Books\"]"));
menuOption.click();
I have reached on the page. But dont know how to proceed after that.
URL
http://www.amazon.in/Books/b/ref=nav_shopall_books_all/280-9259056-7717210?_encoding=UTF8&node=976389031
As I can see, the images are getting scrolled, so just wait for the concerned image first and then click on it. I have added a code based on that:
wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[#class='acsux-hero-wrap']//li[2]//img")));
WebElement ele = driver.findElement(By.xpath("//div[#class='acsux-hero-wrap']//li[2]//img"));
ele.click();
In the above code, the driver waits till the visibility of the 2nd image is located under 60 seconds. Then, it clicks on that element.
Similarly you can just replace the number li[2] with "li[1]" for first element, "li[4]" for fourth element, and so on.
Use other attributes such as width or alt
//img[contains(#alt,'Children')]
I was able to click on the highlighted image shown in your screenshot although its a different image with different keywords i reckon you'll need some bonded attribute for that image there to be able to click it regardless of its content or so and that'll be something like know the exact div the img tag this and so on.
hope this helps
Related
enter image description hereAs part of my Selenium (Java) testing i need to make sure that Webelement is located on the left side of the page. In this situation how would you proceed and what action would you take?
Reference is attached
You can fetch the position of the WebElement in x and y coordinates.
Find a comfortable range for the value of x.
You can find a readthrough of this idea on this link
The Code may look like following -
WebElement eExportGridButton = driver.findElement(By.xpath("//*[contains(text(),'Export Grid')]"));
Actions actions = new Actions(driver);
int getX = eExportGridButton.getLocation().getX();
System.out.println("X coordinate: " + getX);
I'm using Foundation 6 to make my websites frontend. Above the header of my website I want to show a promotionbar, which should be closeable / dismisable.
Therefore I'm using a close-button, coming out of the box with Foundation, to hide / dismis the promotionbar.
Now I want, that if the user closes / hides the promotionbar, that (for the rest of the session) the bar will not be shown anymore.
As the closebutton just "hides" the element, the bar will be shown again if I go to another subpage (for example, coming from a blogpost -> going back to the frontpage).
Is there a simple way to keep the bar hidden, after I've clicked on the closebutton for the rest of the session?
If the user stops by another day, the bar should be shown again.
https://foundation.zurb.com/sites/docs/close-button.html
Thank you in advance!
Thank you #daniel-ruf - I've solved it the following way if anybody is looking for a solution
Give the promotionbar an unique ID (id="promotionbar")
Add a class to the promotionbar (class="hider")
Add display:none, to the class via CSS File (.hider {display:none;})
Add onClick action the closebutton
button class="close-button" data-close="" onclick="promotionhide()">×
in App.js add
var cacheKeyNoPromo = 'promotionhide';
var nopromo = readFromCache(cacheKeyNoPromo);
if (!nopromo) {
document.getElementById("promotionbar").classList.remove("hider");
}
var promotionhide = function() {
writeToCache(cacheKeyNoPromo, true, 24 * 60 * 60 * 1000 /* 1D */);
document.getElementById("promotionbar").classList.add("hider");
};
works for me.
I have a number of Panels which, when expanded, show the corresponding questions for that particular 'Category'
The issue I have is, say for example I answer the questions for the 1st panel, the content will scroll down, eventually hiding the panel... fair enough.
However, when I click on the Next Category (Production Area), I need to the page to scroll back up to the first question in the Category, or maybe even just display the selected category at the top of the page.
Is this possible?
Currently, the user has to continually scroll back if when they select the next Category.
You can achieve it using scrollToElement()
var oPage = sap.ui.getCore().byId("pageId"); // you page ID
var oList = sap.ui.getCore().byId("ListId"); // element ID to which it has to scroll
if (oPage && oList) oPage.scrollToElement(oList, 1000);
Execute the above code inside the panel event expand.
you can try to use this control instead which suits your needs
https://sapui5.hana.ondemand.com/#/entity/sap.uxap.ObjectPageLayout
After trying everything, this is what worked for me.
onExpand: function (oEvent) {
if (oEvent.getParameters().expand) {
var focusID = oEvent.getParameter("id");
var elmnt = sap.ui.getCore().byId(focusID);
elmnt.getDomRef().scrollIntoView(true);
I have some code here that when an image (which is my button) is clicked, a new image randomly appears. This is due to a table I created with some images inside.
local animalPic
local button = display.newImageRect ("images/animalBtn.jpg", 200, 200)
button.x = 250
button.y = 50
local myPics = {"images/animal1.png", "images/animal2.png"}
function button:tap (event)
local idx = math.random(#myPics)
local img = myPics[idx]
local animalPic = display.newImage(img)
animalPic.x = contentCenterX
animalPic.y = contentCenterY
end
button:addEventListener ("tap", button)
The problem with it is the graphics just keep piling up when I click the button. The correct behavior should be -
Button is clicked and an image is shown while removing the previous image. How do I incorporate this behavior? I already tried the removeSelf command and it doesnt work......Any help appreciated.
You declare animalPic each time you enter function. You should declare it once and then remove it and replace it by another.
It should be:
local animalPic
function button:tap (event)
local idx = math.random(#myPics)
local img = myPics[idx]
animalPic:removeSelf()
animalPic = nil
animalPic = display.newImage(img)
animalPic.x = contentCenterX
animalPic.y = contentCenterY
end
When you call display.newImage(), you are adding a new image. The problem is that you need to remove/hide the original one. Perhaps you really need two objects - one for the current image and one for the tap event. When the tap event occurs, hide the old image and display the new one. An alternative would be to load all the images in their own imageRects and then toggle them on and off.
i am using ruby-gtk. There is a notebook in my application. I added textView to scrolledWindow. I want to get textView buffer. My some code
editor = Textview.new
swin = Gtk::ScrolledWindow.new
tab = Gtk::Notebook.new
swin.add(editor)
tab.append_page(swin, Gtk::Label.new("Tab")
tab.get_nth_page(current_page).buffer # wrong because its contain is a scrolledWindow
How can i get editor buffer?
As GtkScrolledWindow is a GtkBin, you can make use of child method to get the widget added as the child. In your case it should return GtkTextView. Try something on the lines of:
tab.get_nth_page(current_page).child.buffer
Hope this helps!