unable to capture tooltip message using selenium web driver - selenium

I am facing one issue while capturing the tooltip message of text box using selenium webdriver.This tooltip is being displayed whenever click on text box.it is not being displayed when mouse over on it.The issue here is,it is not identifying the locator of that tooltip while running(i used xpath).Please help on this.
Thanks,
Murali

first identify the webelement where tool tip is occuring by help of findelement then use getText()
driver.findElement(By.name("xyz")).getText();

Due to lack of some sample html code, its hard to know the exact problem. However I would like to share how I tested tooltip in the past. Tooltip is mostly defined by title attribute of the html element. So to test tooltip of an element, just grab that element and make sure the title attribute matches the tool tip you expect. Keep your test limited to this only and avoid doing any fancy hover stuff etc.
WebElement login = driver.findElement(By.id("login_id"));
String tooltip = login.getAttribute("title");
assertThat("Tool tips did not match",tooltip,equalTo("expected tool tip"));

If you want to capture the username-info message, then use:
String message = driver.findElement(By.id("gmail-address-infomessage")).getText();
If you want to capture the username-error message, then use:
String message = driver.findElement(By.id("errormsg_0_GmailAddress")).getText();

Related

Selenium for VBA - element not found error

I have been using a code since long time , but recently there is a new banner up which is hiding the element that I am trying to click.
Attaching the snapshot of error. The only help I need is I need to click the hidden element( if the browser window is maximized the element is visible).
.
Please help me.
If what you have said is true then you can use the following to maximize the window before clicking:
driver.Window.Maximize
Other options include:
1) Removing the banner
2) Scrolling the element into view
Can't write anything decent for those last two as your code is an image and I don't have a full URL to test with. You also haven't included the relevant HTML.
The "div.container-fluid" element is blocking the button you are trying to click.
You could try some of the following (as being shown here Element MyElement is not clickable at point (x, y)... Other element would receive the click):
prolong the wait before the click
use javascript executor

click on submit button not working in selenium webdriver

I trying to click on the create account button in registration form.
this is how the button locate in the html page:
<div id="submitContainer"><button type="submit" class="large"><span><strong> Create Account </strong></span></button></div>
this is the button xpath:
//*[#id="submitContainer"]/button/span/strong
the problem is that the button don't have id, he locate inside a div.
I try to use by id,xpath,css,name, but all of this not working:
driver.findElement(By.id("submitContainer")).click();
driver.findElement(By.xpath("//*[#id='submitContainer']/button/span/strong")).click();
driver.findElement(By.tagName("Create Account")).click();
driver.findElement(By.className("large")).click();
thanks!
In your examples, except for the last one, you are not targeting the button. Now your last example, should actually locate the button-element:
driver.findElement(By.className("large")).click();
Could you please post the error message you are getting?
Are there more than one element on the page with className "large"?
Make sure the button is in view window, if it is then try clicking on it. Try to wait for the element to load. There might be an issue with your element being loaded into DOM -
driver.wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[#type='submit']"))).click();
Hope this helps.
If you want to use xpath, the correct syntax is
//button[#type='submit']
Use this line below:
Thread.sleep(3000);
I got the result once I used this one. Since some time we need to give some sleep time for the site to load fully to pull the Xpath.
You can use the linkText
driver.findElement(By.linkText("Create Account")).click();
Hope it will work for you.

selenium invalid element state: Element is not currently interactable and may not be manipulated

I have this issue with selenium; I cannot find i textinput : it always raises this exeception:
Element is not currently interactable and may not be manipulated
in this line:
Driver.FindElement(By.Id("ctl00")).Clear();
I try to put waiting like this:
Waiting.Until(driver =>(By.Id("ctl00")));
and
Waiting.Until(ExpectedConditions.ElementExists(By.Id("ctl00")));
but no luck.
If the exception gets thrown on Clear(),
the element is most likely present on the page and the input in a readonly state.
Try to validate XPath first as might be that targeting more than one element.
Due to this, element not currently interactable and may not be manipulated.
I faced same issue and found solution with above as my XPath was locating multiple element which exists on DOM but not page.
Correct the element XPath, error will resolve automatically with adding webdriver wait.
I hit the same error, was also a bit confused, but resolved it using the below wait condition. The elementToBeClickable condition checks that the element is both visible and enabled. Perhaps visibility is enough, but Selenium throws an explicit ElementNotVisibleException, so I'm not sure why I wouldn't get that...
Anyways, I opted to use a more robust wait condition, and it has worked well for me.
wait.until(ExpectedConditions.elementToBeClickable(By.id("myElementId"))).clear();
This happens sometimes when element is not visible. It would happen even when element is visible also.
Try using with different tags like xpath or etc.
You can check the element status using below script
driver.findElement(By.className("")).isEnabled()
It is due to element not visible so apply more wait while performing the action or you can use hardcoded sleep cause sometimes webdriver's wait doesn't work.
You are trying to perform .clear() on a WebElement, which is not an input tag. For example, if you try to do clear on a Span WebElement, You will get Selenium Invalid Element State error.
Waiting.Until(ExpectedConditions.ElementExists(By.Id("ctl00"))); should work.
Set break point at Waiting.Until() line and input $$("#ctl00") in Chrome console to check if the element is existing.
Make the driver to wait until an element is visible.
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOf(element));
Hope this helps!
If waiting for visibilityOf(), elementToBeClickable(), element.isEnabled() doesn't do the trick, try to look at the attributes of your element.
It may have some attributes responsible for read only state, in my case this was aria-readonly and aria-disabled, Hence I created custom wait like this:
webDriverWait.until(webDriver -> webElement.getAttribute("aria-readonly").equals("false") && webElement.getAttribute("aria-disabled").equals("false"));
Use this you will not get this error(might be scroll is not working here so use keypad TAB to move on, my problem got resolved by this)
Actions act = new Actions(driver);
act.sendKeys(Keys.TAB).build().perform();
act.sendKeys(Keys.RETURN).build().perform();
You might be asking an element with the same attribute like duplicate id, name etc.
I My case i was entering password in confirm password TextBox whose Id was "confirmPassword" but the same Id is used for the "Confirm Password" label for that TextBox.
So selenium was trying to perform sendKeys on the label instead of TextBox so getting "InvalidElementStateException", After that i changed the xpath and it worked.
So when you get "InvalidElementStateException" you should first check whether there are any duplicate element available with the xpath you have generated, and that not-interactive element could be a Button, Label or disabled element that causes the exception occurred.
I was clicking on a div element or label to element to clear the text in input tag. Changed my xpath to input tag and then I did not received any exception and the test was clear.

Unable to locate dynamic input element with Selenium

I have a textfield in my application , it gets enabled when i click on it. I am able to do click using CSS but i am unable to enter text when it got highlighted.
I tried using xpath to idenfify the dynamicly but webdriver is throwing an error
"Unable to locate element:
{"method":"xpath","selector":"//input[#class='x-form-field
x-form-text']"}![enter image description here][1]
showed the difference before n after clicking on the field in thescreen shot.
Please help in how to dynamically identify and enter the text in that field
try the following:
String cssSelector = "[class='x-form-field x-form-text']"
//but verify found css selector in firepath, firebug addon in ffox to make sure selenium //locate web element for input properly.
driver.findElement(By.cssSelector(cssSelector)).clear();
driver.findElement(By.cssSelector(cssSelector)).sendKeys("blablabla");
Hope this works for you
Try this code:
String cssSelector = ".x-form-field x-form-text"
driver.findElement(By.cssSelector(cssSelector)).clear();
driver.findElement(By.cssSelector(cssSelector)).sendKeys("blablabla");
Let me know is the above scripting is working or not.

SVG and selenium

Hej Guys
I an using google visualization api to draw stacked bar chart. Its all fine but now i want to test it with selenium but having a hard time finding the elements in the google chart.
For example i want to click on the chart element but everytime i try to find an element by xpath i get exception "OpenQA.Selenium.NoSuchElementException: The element could not be found"
I read that with selenium its tricky to click on the svg images.
Is there anybody who know a solution cuz i m kind of desprate and i havent find a suitable solution on the net by myself.
My chart looks like this:
http://i48.tinypic.com/21o4swx.png
What i am trying todo is:
webdriver.Navigate().GoToUrl("http://localhost:59777/Tests/TestsMainView");
IWebElement element = webdriver.FindElement(By.XPath("/html/body/div/div[2]/div[2]/iframe/html/body/div/svg/g[2]/g/g[2]/rect[5]"));
Actions myAction = new Actions(webdriver);
myAction.Click(element).Perform();
Thread.Sleep(9999);
Thanks :)
Here is some advice that may help you. First your second line of code is should be
WebElement element = webdriver.FindElement(By.xpath("//img[contains(#src,'http://i48.tinypic.com/21o4swx.png')]"))
You had "IWebElement" (this was probably just a typo in your question). I changed the way the element is found searching for matching element instead of starting at the top level and working down. This is a better practice to narrow down the element you are attempting to interact with so that changes to the code don't instantly break your test. Also unless you start an xpath expression off with "//" or "xpath=" selenium Webdriver will not recognize it so even if your path never changed selenium Webdriver wouldn't be able to find it.
If I understand what you are trying to do then you can also remove lines 3-5 and replace them with the following,
element.click();
This will have selenium Webdriver zoom in on the chart provided by your link. I hope this helps
I noticed xpath cannot select anything within an svg tag. I managed to find elements using className or tagName selectors instead or you could even try cssSelectors but I am not sure about that one. Note that you can still use xpath to access parents of a node inside an svg using:
By.xpath("..");
Hope that will help.