Reputation: 397
I am doing an automation project for my organisation. I am using Firefox Web Browser for this purpose. Code is working fine but is stuck at one point in between the program.Problem is related to clicking on a webelement. With selenium code 1.I have to first click on complete task 2. After clicking on complete task submit option appears on webpage and I have to click on submit button as shown in image
.
As seen in this image when I click on complete task it is showing information about complete task element. Next I have to click on submit part but due to this tooltip program is unable to click on submit element.
Following is the Html of Complete task
element
<img class="completeTask" src="pics/transparent.gif" name="WFCompleteTask" onmouseout="tryHideCompleteTask()" onmousedown="MM_swapImage('WFCompleteTask','completeTaskOnClick','pics/transparent.gif',1);showCompleteTask(this);" alt="This will save and submit your order and complete your task. You may not edit this task after you have completed it." title="">
Following is the html of submit element
<td class="completeTaskDropdown"><nobr>submit</nobr></td>
<nobr>submit</nobr>
While debugging the program , program shows it has clicked on complete task and submit button but actually in web browser it has not clicked none of these.I have tried all the possible ways to solve this problem but unable to get proper answer. Following is the a short code snippet for the above task
firefoxProfile = webdriver.FirefoxProfile()
firefoxProfile.set_preference("plugin.state.flash", 2)
firefoxProfile.update_preferences()
driver = webdriver.Firefox(firefoxProfile, executable_path=r'drivers\geckodriver.exe')
actions = ActionChains(driver)
complete_task = wait.until(EC.element_to_be_clickable((By.XPATH, "//img[@name='WFCompleteTask']")))
driver.execute_script("return arguments[0].scrollIntoView(true);", complete_task)
driver.execute_script("arguments[0].click();", complete_task)
submit = wait.until(EC.element_to_be_clickable((By.XPATH, "//nobr[contains(text(),'submit')]")))
driver.execute_script("arguments[0].click();", submit)
I have also tried Actionchains and manual click also-
ActionChains(driver).move_to_element(submit).click(submit).perform()
Also tried
complete_task.click()
submit.click()
But unfortunately no method works for clicking on complete_task and after that submit button. In stack overflow I found some jquery code but that also not works for hiding or removing tooltips. Following is that code
driver.execute_script("""
unction hideTips(event) {
var saveAlt = $(this).attr('alt');
var saveTitle = $(this).attr('title');
if (event.type == 'mouseenter') {
$(this).attr('title','');
$(this).attr('alt','');
} else {
if (event.type == 'mouseleave'){
$(this).attr('alt',saveAlt);
$(this).attr('title',saveTitle);
}
}
}
$(document).ready(function(){
$("a").live("hover", hideTips);
}); """)
But above code is not working. Tried my code in Internet Explorer browser also but same problem arises in internet explorer also. How to hide these tooltips from webpage or if hiding tooltips are not possible than how to get click on both complete task and submit button with the help of automation script.
Note: Previous week this project and click was working fine but due to change in code with ui(addition of tooltips in webpage by team of this tool) this click is not performed
Upvotes: 0
Views: 2255
Reputation: 1
Try if this works:
javaScriptExecutor.executeScript("arguments[0].submit()", webElement);
or try send keys event.
Upvotes: 0
Reputation: 31
I have been troubleshooting a similar issue recently. The hover tooltips text does not disappear after click on the first element, thus failing the subsequent click on another element (as the element is blocked by the tooltips, similar to your case). This issue only happens on Firefox but not Chrome.
I haven't figured out why the hover tooltips text remains on UI after the click. The workaround I found is to use Actions class's click instead of Webdriver's click() for the first element, which will not show the hover tooltips and therefore not blocking the second click.
Upvotes: 3
Reputation: 4177
Try this :
submit = wait.until(EC.element_to_be_clickable((By.XPATH, "//nobr[contains(.,'submit')]")))
ActionChains(drivers).move_to_element(submit).click().perform()
or
submit = wait.until(EC.element_to_be_clickable((By.XPATH, "//nobr[contains(.,'submit')]")))
driver.execute_script("arguments[0].click();", submit)
Note : please add below imports to your solution
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
Upvotes: 0