0

I'm trying to click on a link inside a dropdown menu, but I keep getting a TimeoutException, using XPATH.

test = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div[1]/div[2]/div/ul/li[4]/ul/li[7]/a"))) driver.execute_script("arguments[0].click();", test) 

But if I try to click on the Log Out option the script sometimes works.

logOut = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div[1]/div[2]/div/ul/li[7]/ul/li/a"))) driver.execute_script("arguments[0].click();", logOut) 

There are 3 dropdown menus. The test is in a menu with some 12 options and the Log Out is in another by itself. I want to understand what I'm doing wrong.

Here's the code for the menus.

<body> <div class="container-fluid"> <div class="row headerLogo"> <!--<header class="navbar-default navbar-static-top headerLogo">--> <div class="col-md-2"> <div class="vericaltext">WIISCPRD23V</div> <a href="/Home" id="linkHome"><img src="/Content/images/Logo_menu2.png" class="logoSea" alt='SEA' /></a> </div> <div class="col-md-10"> <div class="row flat-nav"> <li class="color20 effect3"> <a><i class="fa fa-comments-o fa-2x"></i><span>Peq</span></a> <ul class="column-based"> <li class="color20" style="font-weight:bold">Question</li> <li><a href="/Quest">Quest</a></li> <li><a href="/Retr">Retr</a></li> <li class="color20" style="font-weight:bold">Vitss</li> <li><a href="/Vit">Vit</a></li> <li class="color20" style="font-weight:bold">BC</li> <li><a href="/Trat">Trat</a></li> <li><a href="/BC">BC</a></li> <li class="color20" style="font-weight:bold">CAD</li> <li><a href="/Cad">Ant</a></li> <li class="color20" style="font-weight:bold">Fer</li> <li><a href="/Add">Add</a></li> <li><a href="/Emp">Emp</a></li> <li><a href="/Est">Est</a></li> <li><a href="/Seg">Seg</a></li> <li><a href="/Rec">Rec</a></li> <li><a href="/Cal">Cal</a></li> </ul> </li> <li class="color49 effect3"> <a><i class="fa fa-envelope-o fa-2x"></i><span>E-mails</span></a> <li class="color5 effect3 divLogout"> <a> <div style="width:100%;padding-top:15px"> <div class="divAlinhadaEsquerda"><i class="fa fa-user-circle fa-3x"></i></div> <div class="divAlinhadaEsquerda"> <div class="fontNomUsr">xxx</div> <div class="fontUser">xxx&nbsp;&nbsp; </div> <div class="fontUlti">xxx</div> </div> </div> </a> <ul class="column-based"> <li><a href="/Home/Logout"><i class="fa fa-power-off"></i><span>Sair</span></a></li> </ul> </li> </ul> 
3
  • Can you show us the DOM? Is it created dynamically?
    – Jeppe
    CommentedNov 21, 2019 at 18:36
  • Are you trying to click on a Add link ?CommentedNov 21, 2019 at 18:55
  • The one I'm trying to click on is ' <li><a href="/Trat">Trat</a></li>'
    – Luck
    CommentedNov 21, 2019 at 18:57

1 Answer 1

1

Your xpath is incorrect, please try below solution : Solution 1:

from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC PesquisasElement=WebDriverWait(browser, 10).until( EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), 'Pesquisas')]"))) TratamentoElement=WebDriverWait(browser, 10).until( EC.element_to_be_clickable((By.XPATH, "//a[@href='/ManterBC']"))) #Create the object for Action Chains actions = ActionChains(driver) actions.move_to_element(PesquisasElement).move_to_element(TratamentoElement).click() actions.perform() 
10
  • I'm still getting TimeoutException, unfortunately. Also, is there a typo in li[@claass='color20 effect3']? I edited to @class.
    – Luck
    CommentedNov 21, 2019 at 19:25
  • @Luck: There was a typo in the xpath, which I just corrected.CommentedNov 21, 2019 at 19:26
  • I tried both ways, but neither seems to be working. I keep getting TimeoutException.
    – Luck
    CommentedNov 21, 2019 at 19:51
  • Sorry, that wouldn't be possible. But I posted the code as it is, changing only minor stuff that's not important in this case like classes name.
    – Luck
    CommentedNov 21, 2019 at 19:55
  • @DipakBachhav I tried, but it still doesn't work. I've tried to click other links on the page and they all work.
    – Luck
    CommentedNov 22, 2019 at 11:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.