1
我想要去http://ted.com/talks,點擊「Topics」下拉菜單中的「See All Topics」,然後點擊隨機的字母標題,如「C」或「DE」 。但是,我不知道如何在該特定字母標題的模式彈出窗口中找到該元素。用python進行web瀏覽selenium:找到模態元素
這是信標題元素的樣子,當我點擊「檢查元素」:
<li class="topic-select__range">
<a class = "topic-select__range__link" href="#" data-index="0">A-B</a>
</li>
<li class="topic-select__range">
<a class = "topic-select__range__link" href="#" data-index="1">C</a>
</li>
<li class="topic-select__range">
<a class = "topic-select__range__link" href="#" data-index="2">D-E</a>
</li>
... etc.
我的程序可以得到所有以查看所有主題只是罰款的方式,但變得無法定位元素的錯誤,當我嘗試點擊字母標題。這是我的代碼片段到目前爲止:
# Each header is assigned a number. A header is picked at random, and clicked.
# [ERROR: Cannot locate element.]
random_letter = random.randint(0, 8)
topics_window = browser.find_element_by_class_name("select-modal__content topic-select") # error here, when program tries to find modal popup or tags within it
letter_headers = topics_window.find_element_by_class_name("topic-select__range__link")
letter_headers[random_letter].click()