[Python] click is not working in selenium due to presence of tooltip in web browser. How to...

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    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.[​IMG]

    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. [​IMG]

    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

    Continue reading...

Compartilhe esta Página