当前位置: 动力学知识库 > 问答 > 编程问答 >

Not able to get Python Selenium to click a tabmenu using xpath

问题描述:

HTML of the webpage I am trying to automate

I am trying to click the Link called 'Network'. I used the following statements but I am not able to get to work as it throws me the following error:

Error I get when I run the py script

Here is the command I used:

eleme=driver.find_element_by_xpath("//div[@id='maincontainer']//div[@id='tabmenu']//div[@class='tabmenu1']//ul[@class='tabmenu l1']//li[@class='tabmenu-item-network']//a[@href='Network']")

eleme.click()

网友答案:

Your xpath query is not good (href attribute is incorrect) so element can't be found, try with driver.find_element_by_xpath("//div[@id='maincontainer']//div[@id='tabmenu']//div[@class='tabmenu1']//ul[@class='tabmenu l1']//li[@class='tabmenu-item-network']//a[text()='Network']")

Or even better, driver.find_element_by_xpath("//div[@id='maincontainer']//a[text()='Network']")

EDIT: You can click on link with driver.find_element_by_link_text('Network')

You should really check WebDriver API http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement

分享给朋友:
您可能感兴趣的文章:
随机阅读: