JMeter Groovy - WebDriver Sampler script failed with Response Code 500 - selenium-webdriver

I am not sure why keep failed with Response Code 500 on my script. Please is my sample code and error messages. Please kindly advise. Many thanks.
Error Messages:
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1612415604534,36638,jp#gc - WebDriver Sampler,500,"javax.script.ScriptException: org.openqa.selenium.ElementNotInteractableException: element not interactable
(Session info: chrome=88.0.4324.146)
Sample Code:
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
WDS.sampleResult.sampleStart();
WDS.browser.get("https://uat-testing.com/");
sleep(10000);
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[#type='text']")).sendKeys("xxxx#testing.com");
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[#type='password']")).clear();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//input[#type='password']")).sendKeys("xxx#xxxx");
WDS.browser.findElement(org.openqa.selenium.By.xpath("//button/span")).click();
sleep(20000);
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[10]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[16]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[3]/li/span")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//div[5]/div/div/div")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[contains(#id,'dropdown-menu-')]/li")).click();
WDS.browser.findElement(org.openqa.selenium.By.xpath("(//button[contains(#type,'button')])")).click();
sleep(30000);
WDS.sampleResult.sampleEnd();

This ElementNotInteractableException means that the element you're trying to work with cannot be used by WebDriver
Thrown to indicate that although an element is present on the DOM, it is not in a state that can be interacted with.
Most probably it's "covered" by other DOM element so the options are in:
Use Explicit Wait for "waiting" until the element can be accessed (by the way you should also consider replacing your "sleeps" with the explicit waits as it's kind of a performance anti-pattern)
Instead of trying to work with particular this element you might want to interact with the one which hovers it, to wit change locator to another one
And finally you can use JavaScript Executor in order to perform the "click" by means of JavaScript
More information on WebDriver Sampler: The WebDriver Sampler: Your Top 10 Questions Answered

Related

Cannot get XPath selector to work using Robocorp Selenium library

I am attempting web automation with a platform called Robocorp using the Selenium library.
When I run my program, I have no issues until I encounter this page where I am trying to get the program to click on the icon that says SQL.
I want the <a> element with the #href attribute.
Here are some (of many) XPaths I have tried that have all failed:
xpath://a[contains(#href,'sql_form.jsp')]
xpath://*[text()='SQL']
xpath://a[#target='frame2]
Snapshot of the element:
I circled the element in red ^^^
I cannot get the selector to be recognized on this page. I have tried adding delays, waiting until the element is active, waiting until the element is visible, etc.
Nothing seems to work.
Here is an image of the elements I am trying to select.
(The link in the href element takes me to the page I am trying to access).
I thought that the third one would for sure work but is still failing.
I am using a platform called Robocorp which only needs the raw selector to work (CSS or XPath)
I was unaware that iframe needed to be handled differently or that it even existed
https://robocorp.com/docs/development-guide/browser/how-to-work-with-iframes
I first needed to switch frames.
To identify the element with text as SQL you can use you can use either of the following locator strategies:
Using Wait Until Element Is Visible:
Wait Until Element Is Visible xpath=//a[starts-with(#href, 'sql_form.jsp') and #target='frame2']/font[text()='SQL'] 10 seconds
Using Wait Until Element Is Enabled:
Wait Until Element Is Enabled xpath=//a[starts-with(#href, 'sql_form.jsp') and #target='frame2']/font[text()='SQL'] 10 seconds
References
You can find a couple of relevant detailed discussions in:
How to click a row that has javascript on click event in RIDE
Robot Framework: Wait Until Element Is Visible vs. Element Should Be Visible, which one is better to use?

JMeter jp#gc-WebDriver Sampler Element Name is dynamic

I tried to write some code in JMeter WebDriver from Chrome. And I find the ID Name is dynamic. When reload the Chrome Browser, the name will be changed
Ex:
1st Load:
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[#id='dropdown-menu-2724']/li")).click();
2nd Load:
WDS.browser.findElement(org.openqa.selenium.By.xpath("//ul[#id='dropdown-menu-3607']/li")).click();
It will cause the error with Element not found messages.
If there is no other way of uniquely identify the element by other means (text, parent, child, whatever) you can use XPath contains() function to do a partial match on the selector.
Something like:
//ul[contains(#id,'dropdown-menu-')]/li
You might also find The WebDriver Sampler: Your Top 10 Questions Answered article useful.

Appium: Element is not interactable error is getting displayed while tapping on the checkbox

Tried: xpath= //*[#id="mktoCheckbox_52362_0"],
Console Error: Element is not interactable.
Tried: Xpath= //[#id="mktoForm_2768"]/div[10]/div[1]/div[2]/div[2]/label,
console error: Element is not interactable.
Tried: xpath= //*[text()='I agree to the '],
clicking on 'License Agreement' link and open pdf file in other tab.
Applied all the above xpath but still got no result. Please provide some solution to this problem.
Assuming you're trying to automate this page: https://info.couchbase.com/couchbase_server_mobile.html
If you want to open the license agreement in a new tab - the relevant XPath would be
//a[text()='License Agreement']
If you want to tick the checkbox associated with the license agreement you need this one:
//input[#name='termsandConditions']
In both case it's better to use Explicit Wait to ensure that the element is clickable prior to attempting to interact with it via i.e. ExpectedConditions.elementToBeClickable() function
Going forward if you're working on mobile automation you can consider using Appium Studio which provides Copy Unique XPath feature, it can make your life easier when it comes to defining an element locator

Are there any tools for recording web browser events for seleniumn2?

I am looking for something very simple. It can use the Selenium IDE recording tool, but it does not allow me to pick what kind of locators I get.
I want to use:
driver.findElement(By.className(str))
to locate things. All I need is something which watches which UI elements on a web page get clicked and writes out the class attributes of those tags.
If I use the Selenium IDE recording (and export to the right type of thing), I get:
#Test
public void testNav() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("3.1.1.5.1.1")).clear();
driver.findElement(By.name("3.1.1.5.1.1")).sendKeys("dan");
driver.findElement(By.name("3.1.1.5.1.5")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.linkText("Categories")).click();
driver.findElement(By.linkText("Create a Category")).click();
driver.findElement(By.linkText("Cancel")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.cssSelector("a.DisplayAdminProductsLink")).click();
driver.findElement(By.linkText("Product1")).click();
There are problems with this. First, it is not give me any By.className() calls. Why? Those first 3 calls will not help me. The framework I am using puts arbitrary things into the name. How can I get it to see the class attribute?
There actually are unique words in the class attribute of all of the above tags. I design my apps so that this is so. Yet it will not use them.
Earlier I asked:
Why is it doing a "driver.findElement().click()"? This is fragile and does not
end up working.
What I need is:
elt = driver.waitFor(By.className("c")); elt.click();
This will work reproducibly.....
I am considering to be removed from the question, as the findElement() code does work. You need to set a general time-out on the driver. It is not very obvious that this can be done, but it can.
So, continuing on....
I can go to the "Options" and change the order of the "Locator Builders" in eclipse. I can put "css" at the top. Then I get:
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).clear();
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).sendKeys("dan");
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.5\"]")).click();
The tags are like:
<input class="form-control LoginUsernameField" ... />
But it does not see the class attribute.... Or I can do this manually.
Selenium looks for a unique identifier to identify elements in a webpage. classNames are a very less desired option for this purpose as they are generally not unique. Ids and names on the other hand are generally unique. This might be the reason why Selenium IDE is not selecting classNames and going for other identifiers.
Selenium IDE records user actions. You would have clicked on the element for Selenium IDE to identify it and that is why you are getting driver.findElement().click().
If you want to wait for element to wait you can try implicit wait.
When you want to use driver.findElement(By.className(str)), are you sure that there is one and only one element in the webpage that is associated with a className? If that is the case you can modify the webdriver code manually to use className.

Selenium WebDriver cannot locate element within an iframe, and throws NoSuchElementException

I realise there are several queries on here for this same problem but none of them provide a solution to my particular problem.
I am running a web driver test that tries to fill out a form for a mail website to find postcodes based on address details. I keep getting this error when trying to locate the first text box:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#ctl00_BodyContent_txtBuildingNumber"}
I have used xpath and the id to try and locate the element but I keep getting the error. I can see that this element is present when the webdriver is running and I have been able to locate another text element on the page and enter text, but I keep getting this error for this field and other fields within the frame.
I am guessing that the problem must be to do with the fact that this field is part of an iFrame.
I have used implicit waits within the test but with no success. I still get the error.
By the sounds of it you'll need to first switch to the iframe element that contains the element that you want to interact with. (Although without seeing the relevant HTML this is a bit of an extrapolated guess).
driver.switchTo().frame();
eg:
driver.switchTo().frame(1);
driver.switchTo().frame(driver.findElement(By.id("id")));
When you've finished interacting with the elements within the frame, you'll need to switch back to the main webpage.
driver.switchTo().defaultContent();
Check your xpath .
try to use simple
driver.switchTo().frame(1);
with wait statement.
sorry a little correction the following worked for me
driver.switchTo().frame(driver.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button i was trying to click was located. (driver is of type WebDriver i.e WebDriver driver ) thank you
The following worked for me
driver.switchTo().frame(myd.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button I was trying to click.(driver is of type WebDriver i.e WebDriver driver)
thank you
you can use wait statement and after using the wait statement use simply
driver.swithcTo().frame();

Resources