0
votes

I am studying web crawling with selenium and I found some error.

This is my coding as follows.

from selenium import webdriver as wd
main_url = 'https://searchad.naver.com/'
driver = wd.Chrome(executable_path='chromedriver.exe')

and I logged in

# access main url2

main_url2 = 'https://searchad.naver.com/my-screen'

# close popup window
driver.find_element_by_css_selector('body > my-app > wrap > welcome-beginner-layer-popup > div.ly_main_pop > div.pop_top > a').click() 

# main3 page access
driver.find_element_by_css_selector('.btn_area>li').click()

# click tool menu bar
driver.find_element_by_css_selector('#navbar-common-header-collapse > ul > li:nth-child(3) > a > span.ng-binding.ng-scope').click()

from the last coding(# click tool menu bar), there is a error as Error message:

Message: no such element: Unable to locate element. Both Css selector and xpath are errors.

This is the resources codes before I click the mouse on '도구' as follows.

<a class="dropdown-toggle ng-scope" ng-if="menu.items" href="" data-toggle="dropdown" role="button" aria-expanded="false"><!-- ngIf: menu.gnb != "billing" --><span ng-if="menu.gnb != &quot;billing&quot;" ng-bind-html="menu.translationId | translate" class="ng-binding ng-scope">도구</span><!-- end ngIf: menu.gnb != "billing" --><!-- ngIf: menu.gnb === "billing" --><span class="ico-dropdown-arrow"></span></a>

<!-- ngIf: menu.gnb != "billing" -->

<span ng-if="menu.gnb != &quot;billing&quot;" ng-bind-html="menu.translationId | translate" class="ng-binding ng-scope">도구</span> 

After I click the menu '도구', I can find sub-menu of '키워드 도구'. This is also the codes of '키워드도구'.

<li ng-repeat="submenu in menu.items track by $index" ng-class="{ divider: submenu === &quot;divider&quot;, disabled: submenu.disabled }" class="ng-scope"><!-- ngIf: submenu.disabled --><!-- ngIf: submenu !== "divider" && !submenu.disabled --><a ng-if="submenu !== &quot;divider&quot; &amp;&amp; !submenu.disabled" data-click-logger="" data-click-id="click.tool.keyword-planner" href="/customers/668860/tool/keyword-planner" ui-sref="tool.keyword-planner(vm.getParams({customerId: customerId}, submenu.params))" ui-sref-opts="{reload: submenu.reload}" ng-bind-html="submenu.translationId | translate" class="ng-binding ng-scope">키워드 도구</a><!-- end ngIf: submenu !== "divider" && !submenu.disabled --></li>
<!-- ngIf: submenu.disabled -->
<!-- ngIf: submenu !== "divider" && !submenu.disabled -->
<a ng-if="submenu !== &quot;divider&quot; &amp;&amp; !submenu.disabled" data-click-logger="" data-click-id="click.tool.keyword-planner" href="/customers/668860/tool/keyword-planner" ui-sref="tool.keyword-planner(vm.getParams({customerId: customerId}, submenu.params))" ui-sref-opts="{reload: submenu.reload}" ng-bind-html="submenu.translationId | translate" class="ng-binding ng-scope">키워드 도구</a>

enter image description hereenter image description here

1
Don't do this. Please read why a screenshot of HTML or code or error is a bad idea. Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. - undetected Selenium
I didn't know it is not a good way to show the Html or code. so I copy the code. Thank for your comment. - 문정아

1 Answers

0
votes

Selenium has a few functions to wait for the elements to load. Read about selenium.webdriver.support.expected_conditions.

Expected conditions wait around 30 seconds on default for an element to show up on the page. Pretty useful if you're clicking around on the websites.

The documentation has a pretty good example.