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.re-content.search-mode-content > 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>
                        </div>

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 27, 2018 in Selenium by Shubham
• 13,490 points
2,691 views

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 27, 2018 by nsv999
• 5,500 points
Hello @nsv999 @Shubham,

I am facing the same error - I login into my project page and the landing page has a link that am trying to click - but get the error noted above.

Any insights into what else could be wrong?
Hey,  it heavily depends on a use case, please elaborate regarding your query with the code snippet you have used. However, you could try using XPath instead of the CSS selector though along with the explicit wait and check if that works.

Hello,

Have you tried increasing the timeout in wait = WebDriverWait(browser, 10)to a larger number to see whether that reduces your timeouts? You can put a try/except block around waiter.until(EC.visibility_of_element_located(...)) to explicitly handle timeout exceptions more gracefully.

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,090 points
2,102 views
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
1,763 views
0 votes
2 answers

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,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,875 views
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
• 28,140 points
1,431 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP