Unable to locate dynamic input element with Selenium - 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.

Related

Selenium unable to locate an element

I'm trying to locate an element with Selenium. But it gives an error saying:
Unable to locate an element with the xpath expression //li[normalize-space()='Don't check credit card BINs'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//li[normalize-space()='Don't check credit card BINs']' is not a valid XPath expression.
I've tried searching the element by inspect and indeed the element cannot be read/found. Is there a special way on writing code for Can't word? Because I suspect that ' symbol cannot be located by selenium.
Here is the dropdown menu that I want to locate (the Don't check credit card BINs menu):
As you can see above, that the specific text is not found by xpath.
You are missing "" in your xpath, as I can see this in you HTML source, also to ignore apostrophe in Don't you can try below
"//li[normalize-space()=\"Don't check credit card BINs\"]"
If this does not work you can try below one too.
"//li[contains(text(),\"Don't check credit card BINs\")]"
Here are some things you can try.
Try using javascript executor, happened to me a few times I can't click a dynamically loaded element with selenium builtin selectors but I was able to click them with selenium js executor
Use absolute xpath, helpful where relative xpath / css selector fails. You can use chrome extensions to get absolute xpath
Hope this helps.

Unable to get specific element on a page, using xpath for a Selenium script

enter image description hereI am having difficulty locating input fields on a form, that has another component embedded.
I can navigate to the beginning of the component, but am unable to locate anything inside the component, using xpath , css location etc...
Even if I inspect the element in chrome, and copy its xpath or css (right click, copy xpath/ selector) and try that path , the element is not found.
There is a #shadow-root element, which I think may be causing the issue ?
See screenshot of where I can locate beginning of component, the selector i am using and the input field i would like to locate
Any ideas/suggestions very welcome
enter image description here

WebElement is identified through xpath in the developer console but the element wont be identified through selenium findElement method

The html element Im trying to locate is the "Shared" link.
I wrote a dynamic xpath to locate the element and it shows as the element was identified in the developer console.
But when i use the xpath that i wrote in the developer console to locate the element using selenium, it does not locate the element.
The method i used to check if it locates the element is shown below.
I could not figure out why this issue occurs, Is it because of a issue in the xpath that i have written or because of another issue?
Code you can try out is :
new WebDriverWait(driver,10).until(ExpectedConditions.elementToBeClickable(By.xpath(" your Xpath ")));
driver.findElement(By.xpath("your Xpath")).click();
The Xpath you have written would work if only one title is present on current page.
driver.find_elements doesn't have attribute to click() so use driver.findElement instead of Elements

Xpath seem to be right when i use chrome but fails on selenium

I am trying to find the text box in the image below
My xpath using chrome is
div[#id='element.problem.short_description']
div[#class='col-xs-10 col-md-9 col-lg-8 form-field input_controls']
still it fails on selenium.
the code is here on the webpage. I Couldn't copy it for some reason, so attaching a screenshot of it
Because you're not looking at the text field.
All you need is //input[#id='problem.short_description']

unable to capture tooltip message using selenium web driver

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();