Can't find an element Using Selenium

0 votes

My code is:

browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
data = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#search_result_former > > div.list-container > ul > li:nth-child(1) > div > div.item-footer > div > a:nth-child(1)')))

The HTML is:

<div class="btn-group clear">
                        <a href="javascript:;" class="btn btn-operation" role="detail">详览</a>
                        <a href="javascript:;" class="btn btn-operation" role="lawState" an="CN201820052763" pn="CN207117855U">法律状态</a>
                        <a href="javascript:;" class="btn btn-operation" role="proposor" _name="信阳农林学院;" _address=" 河南省信阳市羊山新区新24大街信阳农林学院;" _zipcode="464000;" _country="">申请人</a>
                        <a href="javascript:;" role="addAnalysis" class="btn btn-operation">+ 分析库</a>
                        <a href="javascript:;" role="favorite" class="btn btn-operation">收藏</a>
                        <a href="javascript:;" role="translate" _id="CN201820052763.420180316XX" class="btn btn-operation btn-translate">翻译</a>

The result after I run my code:

*raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:* 

Actually, I can see the element. I mean, the element has been loaded. I have tried XPATH, but it doesn't work.

Mar 26, 2018 in Selenium by Shubham
• 13,380 points

1 answer to this question.

0 votes

The reason you can't locate the item is because a new window is opened and I need to switch to the new one. 

windows = browser.window_handle browser.switch_to.window(windows[-1])

Do let me know if this works!

answered Mar 26, 2018 by nsv999
• 5,510 points

Related Questions In Selenium

0 votes
1 answer

Locating an element by value using css selector using Selenium WebDriver

Below code will help By.cssSelector("td[class='someclass'][value=' ...READ MORE

answered Apr 9, 2018 in Selenium by coldcode
• 2,050 points
0 votes
1 answer
0 votes
1 answer

Wait for an element to be accessible using Selenium WebDriver

You can try out the below code: ...READ MORE

answered May 18, 2018 in Selenium by Atul
• 10,240 points
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,870 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
0 votes
2 answers

Finding an element in Selenium

Hi, ​both find_element_by_xpath(xpath) and find_element(By.XPath, xpath) serve the ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 27,920 points
0 votes
1 answer