I encountered a problem automating a test-procedure on my website. I there have a list of items and - to add a new one - a modal openes. Everything's fine til then - the RobotFramework fills out the checkboxes and inputs with text, but when it comes to the "Save"-button, Chrome and Firefox response differently.
Chrome does everything correct, closing the modal and saving the new item. Firefox on the other hand seems to click the button too, but nothing happens. The code "behind" the button is as follows:
<button id="submitSomething" type="submit" name="someName"
value="Save" onclick="window.wishlist.editPreSubmit(this, event)">Save</button>
Python 2.7.x (latest) 32 bit
wxPython 2.8 32 bit
geckodriver latest 64 bit
chromedriver 2.45
I tried somehing like:
Execute Javascript document.querySelector("#submitNew").click()
instead of
Click Button id=submitSomething
but without a change on Firefox sadly. Every tiny help would be greatly appreciated :)
Edit:
If I use
document.querySelector("#submitNew").click()
in the console of the browser which was opened from robotframework, it does not work either (firefox) and I get a warning:
form posted in windows-1252-codec, should be changed to utf-8
Br
To click the desired element you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Wait Until Element Is Visible:
Wait Until Element Is Visible xpath=//button[#id='submitSomething' and #value='Save'][contains(., 'Save')] 20 seconds
Set Focus To Element xpath=//button[#id='submitSomething' and #value='Save'][contains(., 'Save')]
# invoke click
Wait Until Element Is Enabled:
Wait Until Element Is Enabled xpath=//button[#id='submitSomething' and #value='Save'][contains(., 'Save')] 20 seconds
Set Focus To Element xpath=//button[#id='submitSomething' and #value='Save'][contains(., 'Save')]
# invoke click
Related
I am trying to go to the below URL
https://twitter.com/explore
Enter HBO Max in the text box which I locate using
By.cssSelector("input[placeholder='Search Twitter']")
and then I want to select the HBO Max option that appears in the dropdown. My locator for the element to be selected is
By.xpath("//div[#role='option']//li/div/div[2]")
Sometimes the element gets clicked and I go to the new page, sometimes not. I have in my framework waited for the element to be clickable using WebDriverWait. The element is both visible and enabled because I print these values before I click the element.
Additional debugging steps performed -
Click using JavaScript seems to have the same behavior.
I believe I am using the right locator because the mouse event gets generated for this element.
Thread.Sleep seems to work suggesting that perhaps a timing issue
Any inputs would be great.
try:
myElem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'ID')))
print("Page is ready!")
except TimeoutException:
print("Loading took too much time!")
Try this !
what it does : It wait until the specific element of the site is loaded. If it takes more time than specified will just give you an output as "loading took too.........."
You can modify the time required to wait.
I am trying to click a row that has a javascript onclick function in RIDE IDE by using Robot Frame Work with Selenium2 library.
<tr class="lstrow" onclick="javascript:selectItem(this);" onmouseover="javascript:this.className='rowhover';" onmouseout="javascript:this.className='row';">
When i perform click event at following xpath, it says element at path not found.
//*[#id="myList"]/tbody/tr[0]
By inspecting the element, I can confirm this row is there. Also tried to pin point the 'rowhover' class at this xpath but still not successful. Not even sure if I really can select a specific class at a specific xpath.
//*[#id="myList"]/tbody/tr[0][contains(#class,'rowhover')] //Not sure if it is right
The desired element is a JavaScript enabled element so you need to induce wait and you can use either/both (clubbing up) of the following solutions:
Python Solution
Wait Until Element Is Visible:
Wait Until Element Is Visible xpath=//tr[#class="lstrow"] 20 seconds
Set Focus To Element xpath=//tr[#class="lstrow"]
# invoke click
Wait Until Element Is Enabled:
Wait Until Element Is Enabled xpath=//tr[#class="lstrow"] 20 seconds
Set Focus To Element xpath=//tr[#class="lstrow"]
# invoke click
You can find a detailed discussion about Wait Until Element Is Visible and Wait Until Element Is Enabled in Robotframework: Selenium2Lib: Wait Until (…) Keywords
Reference: Selenium2Library
I'm experiencing a very annoying bug with selenium IDE, firefox and html runner.
I'm testing a single page, with an inner iframe dinamically loaded after a click on a button.
I can see the iframe content by selectFrame | id=frame1 and all is ok.
Then, i click a button on the frame and this cause the iframe to be unloaded.
After that, i can't access to anything in the main page, even if i do:
selectWindow | title=, the command is ok, that is the same as SwitchTo().DefaultContent(), but it seems all the content is no more here, every xpath lookup fails.
I tried assigning a button id to a variable BEFORE loading and unloading the iframe with assignId | //button[2],
but when later i use the variable to access the button i get
can't access dead object
It seems that unloading the inner iframe all the content in the outer window was lost, but the page is already there ( iput a waitForElementPresent to wait indefinitely and i see the page with all its stuff.
Any ideas ?
Firefox 59
Selenium IDE 2.9.1
Selenium Gecko Driver 0.20
Selenium html runner 3.10
Thanks a lot.
Good day everyone,
I need your help in this method. I have a web page that will have a loading screen UI when the page loads, and I'm waiting for it to finish before clicking a button.
Here is my code:
#Step("Go to Audit Inquiry Screen")
public void launchAuditInquiry(){
WebDriver webDriver = Driver.webDriver;
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));
WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
auditInquiryBtn.click();
}
My issue is sometimes, this code works fine. It will wait for the loading ui div to be invisible before clicking the button. But sometimes it will produce this error:
Error Message: org.openqa.selenium.WebDriverException: unknown error: Element <a class="module-item" href="/audit/inquiry">...</a> is not clickable at point (822, 436). Other element would receive the click: <div class="loading-container" style="display: flex; opacity: 0.899842;">...</div>
I tried adding another explicit wait before clicking the button to be sure, like this:
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));
WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Audit Inquiry")));
auditInquiryBtn.click();
But it will sometime produce the same error above, and sometimes it will work fine.
I'm just confused on how to remediate the issue.
Thank you guys for the comments, especially this: Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click
It was helpful, but some items there, I have already tried, but did not work as well. The part that I did check was one item there and also a comment here also which is to force a click:
new Actions(driver).moveToElement(auditInquiryBtn).click().perform();
But I'm having second thoughts on this because, a scenario may happen that when the loading container div is still overlaying the page, then I forced clicked the submit button, it will also produce another loading container div, and I'm not sure what will happen if there are two loading container div present.
Now, my solution on this is to adjust the sleep timer of the wait function:
WebDriverWait wait = new WebDriverWait(webDriver, 10, 2500L);
It now works because it gives the loader div time to generate before the first check of wait. 500 ms was a bit fast for the loader to render. I'm still testing this but if it didn't work, I might do the solution above.
Thanks again.
First thing to try is remove the invisibilityOfElementLocated wait and just use elementToBeClickable. I've never really trusted what Selenium considered "visible" and "invisible".
I've had issues in the past where the element to click on was completely off screen, so Selenium automatically scrolled until it was considered in the viewport. But because of a floating footer, it didn't scroll enough and was still behind the footer so could not be clicked on. It was still considered "visible" because it was in the viewport.
But, if you're sure, you can try forcing a click at a coordinate instead of an element.
new Actions(driver).moveToElement(auditInquiryBtn).click().perform();
I have a simple submit button on a page that I need to send a click for it but this button is at the bottom of the page and does not appear unless a user uses the browser vertical scroll bar to reach it !!
so when I use this C# code I get error element is not visible so how I can solve this problem ?
driver.FindElement(By.Id("submit")).Click();
You could scroll down using javascript. Something like this should do the work.
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
Selenium Webdriver implicitly scroll to the element, if it is visible. You can wait for the visibility of the element and then perform the click operation. In Java, we can wait for the visibility using following code:
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(driver.findElement(By.id("submit"))));
In the above code, Webdriver will wait for 60 seconds, for the required element to become visible. If within 60 seconds, the element does not appear, then it will fail with timeout error. Once, the required element is visible, it can be clicked.
If it's not visible by you, it is not render by the browser used through your selenium driver.
I recommend you to simulate a scrolling to ensure your item will be visible, or do a simulation on a bigger resolution ?
Eventually you can consider switch to an headless driver...
I found the problem there are two elements in the page with id="submit" !! I used Name and now it work fine, thank to all.