I am having some troubles to locate an element with Selenium.
The page html where I'm looking for it is:
enter image description here
Specifically, I want to get the input with id='filtroDNI'. For this I'm using
WaitFluent.xpathClickable("//input[#id='filtroDNI']")
But I'm getting Method threw 'org.openqa.selenium.TimeoutException' exception. because Expected condition failed: waiting for visibility of element located by By.xpath: //input[#id='filtroDNI'] (tried for 11 second(s) with 3000 milliseconds interval)
However, If I try to get some elements above this one, I can reach the div with id='content-wrap' by using following code:
WaitFluent.xpathClickable("//div[#id='content-wrap']")
Do you have any idea of what can be happening? Also I tried with alternative xpaths but the results are the same.
Also, the page is throwing an error but after consulting it with the dev team, they said it has nothing to be with my question, the error is this one:
Uncaught TypeError: Cannot read properties of undefined (reading 'hasChildNodes')
at sorter.sort (script.js:53:12)
at sorter.reset (script.js:43:9)
at sorter.init (script.js:37:8)
at new sorter (script.js:8:77)
at histo.php:277:54
Thanks in advance
Edit:
xpathClickable method code:
/**
* <STRONG>Description:</STRONG>Waits for an element with a given xpath to be clickable.
*
* #param xpath String;
* #return WebElement
*/
public static WebElement xpathClickable(final String xpath) {
return new FluentWait<WebDriver>(myEnvironment)
.withTimeout(IMPLICIT_TIMEOUT)
.pollingEvery(RETRY_TIME)
.ignoring(StaleElementReferenceException.class,
NoSuchElementException.class)
.until(ExpectedConditions
.elementToBeClickable(By.xpath(xpath)));
}
Edit 2:
DEV team already solved the JS issue shown in console, but the xpath cannot be retrieved yet.
Related
I'm getting this error message when selenium/C# program tried to click on an element in a drop down list in Dynamis365.
Inner Exception 1:
InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text(), 'Submitted') because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
(Session info: chrome=87.0.4280.88)
My Code is:
internal void SetValues()
{
findByElement.FindByXPath("//span[contains(text(), 'Submission Pending')]").Click();
findByElement.FindByXPath("contains(text(), 'Submitted')").Click();
}
The HTML is:
<span id="id-bc19d003-2d6a-43ad-8e1b-566ecbb00647-132-statuscode6-statuscode.fieldControl-pickliststatus-comboBox_text-value" class=" ">Submission Pending</span>
I'm trying to click on Submitted choice, which do not show in HTML:DropDownList
Note: The other drop down list choices do not show in html. Only after making a choice (Submitted) it shows up in the html (replaces Submission Pending")
Submission Pending
Submitted clicked
Are you sure the page has fully loaded? Have you read the docs, specifically the 'waits' section (link below for the python version). I had this problem and simply put a 5 second delay into the code and it worked fine.
https://selenium-python.readthedocs.io/waits.html
Alternatively you may find it easier locating the element by id rather than by XPath
FindByXPath("contains(text(), 'Submitted')")
This is not a valid XPath expression! All XPath must start with the slash / character. Perhaps you meant something like:
FindByXPath("//*[contains(text(), 'Submitted')]")
Below line of code worked:
findByElement.FindByXPath("//*[./text()='Submitted']").Click();
This works and returns exactly what I want:
*** Variables ***
${HOME_LOGO}= css=#header > nav > div.header-gutter > div > img
*** Keywords ***
Home logo is visible
Element Should Be Visible ${HOME_LOGO}
${logo_src}= Get Element Attribute ${HOME_LOGO}#src
log ${logo_src}
However, I am getting a WARN when I run it: Using 'Get Element Attribute' without explicit attribute is deprecated
I have tried several approaches, but have not been able to resolve the warn message AND get the information I want into ${logo_src}. I am looking for the img src.
What is the best way to either handle the warn or get the img src from the element in the xpath?
Thank you - I'm very new to robot framework and selenium but not new to test automation. Also new to stackoverflow.
They have changed how this keyword works from when it was originally designed. Instead of appending the attribute to the locator, provide it as an argument:
${logo_src}= Get Element Attribute ${HOME_LOGO} src
(note: there needs to be two or more spaces before src)
I am unable to scroll down to the save button at the end of the page. Have tried using scrollToElement function but it does not work.
The error given :
Test Cases/merchantAdd1 FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.scrollToElement() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject)
This doesn't necessarily mean you are unable to scroll to an element. You are missing a parameter.
The error message is saying you are trying to pass the wrong types of argument to scrollToElement() function. It is expecting a TestObject and an int (timeout in seconds) and you are passing in only the test object.
It should be something like
WebUI.scrollToElement(findTestObject('your test object'), 3)
If you are unable to find Test Object, and it is at the bottom of the page, try scrolling to position high absisse and ordinate.
for example WebUI.scrollToPosition(9999999, 9999999)
Then try click on the Objct
I have tried all the suggestions on stackoverflow but none seems to work. My code works for all other tested log in site but "https://internet-banking.dbs.com.sg/", which is the site I'm trying to write a script to log in and check my bank balance upon request.
My code is as follow:
def page_is_loaded(driver):
return driver.find_element_by_tag_name("body") != None
driver = webdriver.Firefox()
driver.get("https://internet-banking.dbs.com.sg/")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
print(driver.page_source)
email_field = driver.find_element_by_id("UID")
email_field.send_keys(*UID*)
password_field = driver.find_element_by_id("PIN")
password_field.send_keys(*PIN*)
password_field.send_keys(Keys.RETURN)
When I run this, I am returned selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:...
Also, if I check driver.page_source, the result is that of the page.
I'm assuming the line that returns the body tag is the one that is failing. It's because the page hasn't loaded yet so it throws an exception. You should use Expected Conditions, specifically visibility_of_element_located and wait for the UID instead of body.
I'm currently trying to improve my Selenium tests on IE. I would like to use javascript-xpath instead of ajaxslt.
My setUp function is :
public void setUp() throws Exception {
super.setUp(host, browser);
selenium.setSpeed(Constants.DELAY_BETWEEN_ACTIONS);
selenium.windowMaximize();
selenium.allowNativeXpath("false");
selenium.useXpathLibrary("javascript-xpath");
}
When I try to find an element by Xpath, for instance :
selenium.click("xpath=//a[#id='linkLogin']");
I get the error (only when i try to use javascript-xpath):
com.thoughtworks.selenium.SeleniumException: ERROR: Invalid xpath [2]: //a[#id='linkLogin']
What do i miss to correctly use javascript-xpath ?
Thanks for your help.
Have you considered changing your locator strategy away from xpath? I've been using a form of CSS locators that are on average 5 times faster than xpath.