如何使用selenium python3点击一个网页上的第二个按钮?

时间:2016-07-30 10:08:42

标签: python-3.x selenium selenium-webdriver web-crawler

在python,selenium,W​​in 7中工作,我想点击sowcomment按钮之后点击wait按钮,由showmore Comments处理,然后我想要点击from selenium import webdriver from selenium.common.exceptions import NoSuchElementException import selenium.common.exceptions from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC import selenium.webdriver.support.ui as UI driver = webdriver.Firefox() driver.get("http://www.aljazeera.com/news/2016/07/erdogan-west-mind-business-160729205425215.html") wait = UI.WebDriverWait(driver, 10) next_page_link = wait.until( EC.element_to_be_clickable((By.ID, 'showcomment'))) next_page_link.click() wait = UI.WebDriverWait(driver, 20) next_page_link2 = wait.until( EC.element_to_be_clickable((By.LINK_TEXT, 'Show more comments'))) next_page_link2.click() v = driver.find_elements_by_class_name('gig-comment-body') print(v) for h in v: print(h.text) 按钮查看更多评论以获取更多评论。在第一个按钮之后,我能够提取评论。

setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Layout layout = ((EditText) v).getLayout();
                    float x = event.getX() + getScrollX();
                    int offset = layout.getOffsetForHorizontal(0, x);
                    if (offset > 0)
                        if (x > layout.getLineMax(0))
                            setSelection(offset);     
                        else
                            setSelection(offset - 1);
                    break;
            }
            return true;
        }
    });

但是第二个按钮无法点击而是给出例外:

  

selenium.common.exceptions.TimeoutException:

有什么问题?

1 个答案:

答案 0 :(得分:0)

我认为您应该尝试使用 String uid = getCookie("www.liveslibk.com", "uid"); 执行点击操作,如下所示:

execute_script()

希望它有帮助...:)