I'm automating this site:
When I click a button a pop up is displayed. There is a link on the screen to display the pop-up but I don't have anything in my code to click the link this code is commented out.
//Please click to confirm you read and accept the conditions
driver.findElement(By.id("assumptionsConfirmed1")).click();
Please try with xpath i think this might work for you bcz i have seen in resources and xpath look more better than id.
driver.findElement(By.xpath("//a[contains(text(),'assumptions and terms and conditions before procee')]")).click();
Related
I try to click in a button like imagen.
not working using class or xpath
this is the button
this is the inspect from this button.
this is the code trying to click on the button:
driver.findElement(By.xpath("/html/body/div[10]/button")).click();
this is the xpath from the before:
driver.findElement(By.xpath("/html/body/div[10]"));
please could someone help me!!!
Every simple change in the page will cause your code to stop functioning, try to always make use of class or id and navigate to it's siblings/parent nodes.
You can do that in 2 ways
1.By using CssSelector (Right click on the Element in DevTools -> Copy -> Copy Selector)
driver.FindElement(By.CssSelector("CopiedText")).Click()
2.By using XPath and accessing it through it's parent (Example for your case)
driver.FindElement(By.xpath("//div[#class='advertising-layer']/button")).Click()
I experienced the similar issue while accessing a button in a dialog box. I tried with XPath, id, it didn't work but it worked with CSS selector.
By using CSS selector I made the selenium webdriver to click on a button, pick a value from the drop-down in the dialog box, type a value in the text box.
I am not sure why exactly it worked with CSS selector and not with XPath. I'd be grateful if someone has a description for this.
If you want to get CSS selector of a particular element follow the below steps
Open the application in Firefox
open Inspect element, and in the inspector ( the place where you see the HTML code)
Select the element in the page to view the particular code for the inspector by using this button
right click on the highlighted part of the code and hover on copy, you will find CSS selector
Let me know if this works out for you.
As per the HTML you have shared to invoke click() on the desired element you have to induce WebDriverWait and you can use the following solution:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("/div[#class='advertising-mask']//button"))).click();
I'm really having trouble automating the facebook posting process.
My script is simply unable to track the textarea in our news feed correctly.
I've tried different selectors, even the ones suggested by Selenium IDE but got no avail.
Here's a snippet of my code:
//xpath for status update box
WebElement statusUpdateBox = driver.findElement(By.xpath(DemoTestData.XPATH_STATUSUPDATE_BTN));
//click the status update box
driver.findElement((By.xpath(DemoTestData.XPATH_STATUSUPDATE_BTN))).click();
//input data in the status update box
statusUpdateBox.sendKeys(DemoTestData.DATA_STATUSUPDATE_MSG);
WebElement postButton = driver.findElement(By.xpath(DemoTestData.XPATH_STATUSUPDATE_BTN));
//click 'post' button
postButton.click();
The xPath for
DemoTestData.XPATH_STATUSUPDATE_BTN = "html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div[3]/div/div/div[2]/div/div/div/form/div[1]/div/div[2]/textarea";
What am possibly missing?
Thanks a lot. :D
Here is what I've found. When I checked your xpath in my FB page it returned no results. (a very handy tool is a plugin called free simple firepath in firefox, be sure to get it if you don't!)
It seems unlikely that the button has an xpath ending with "textarea" are you sure that is correct?
When you run your test does the text get filled in? If not, the (first) problem is probably the findElement of the textbox.
When I looked some more I found that the css is actually very simple "textarea" . So if you'd use driver.FindElement(By.CssSelector(“textarea”))
that should return the text area.
The button has a bit of a strange css (to me, but I am quite new to this as well), but I beleieve you could find that by the text in it. In my language it says "Plaatsen" It might say something different for you. Check in Firepath!
The something like driver.FindElement(By.XPath("//*[text()[contains(.,'Plaatsen')]]")) should return the button.
I hope it helps! And I hope you found this answer useful, any tips on that would appreciated, it my first time answering something on the mighty Stack Overflow!
Cheers!
Say I have an element (doesn't really matter what. Let's say "//div[#id='tony']/div/span" but any xpath would be OK.
To get the text on a page from this you could do something like
WebElement ele = driver.findElement(By.xpath("//div[#id='tony']/div/span"));
System.out.println(ele.getText());
// Or an our system someone wrote a method so we can get all text in that
// element and everything underneath (part of that element)
System.out.println(getText(ele));
This is fine when you are running the program. But originally when you are writing and debugging with Chrome before you actually write the program. In Chrome you can do right click -> inspect and then in the bottom do a ctrl-f which opens a search box and you can type an xpath and it will highlight it (them) on the page.
Now I swear several months ago when I was debugging I could also have it display the text in that element but I don't remember how? You type something into the search box like get-text(//div[#id='tony']/div/span) but I can't remember or figure it out. Perhaps at the time I was using Firebug and not Chrome?
Does anyone know a way to have it print the text of the element? I know you can eyeball it in the HTML code but what you think is the text and what it actually is is not always the same
I searched for some answers, but came up empty, maybe I'm not wording my question correctly.
Basically I want a hyper link, except it has a java on click listener attached to it, instead of an html link. I have some paragraphs of text and certain words are highlighted, I want the user to be able to click those words and it executes a function.
Any thoughts or website tutorials? Thanks.
You should use the Linkify class to achieve what you want. Here is a full tutorial that will help you
Ok so I have an rss reader that links to articles. One of the sites it links to doesn't have a mobile view. I was wondering if anyone knew if it was possible to set the "zoom" and position of the view once the page is loaded? So for instance if the following link were my article... http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7
Then how could I have the view focus on the article without the user having to zoom in and scroll the the top of the article. Thanks.
I think, you have to use an anchor, which are based on the ids of the HTML code. Then, you have to pass the Id you want to stick to after the url and a #.
With your example, it would give something like that :
http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7#c1256209263986
As the div you are looking for has an id (lucky you cause they don't have all the time)
<div id="c1256209263986" class="iw_component"><div xmlns:esi="http://www.edge-delivery.org
Hope this will help you (Try to click on the link I put, this should open the page at the start of the article.)
I never tried that but have a go a this, and come back to tell me if it worked.