Python 单击没有id的按钮
我有这个密码Python 单击没有id的按钮,python,selenium,selenium-webdriver,xpath,css-selectors,Python,Selenium,Selenium Webdriver,Xpath,Css Selectors,我有这个密码 <a href="#" class="button expanded vote" style="background: rgb(51, 204, 102) none repeat scroll 0% 0%; border-radius: 5px;" onclick="Poll.sendAnswer("Programn2015","Answer1","Answer2")">Vote</a> 要单击文本为“投票”的链接,可以使用以下任一解决方案: css\u
<a href="#" class="button expanded vote" style="background: rgb(51, 204, 102) none repeat scroll 0% 0%; border-radius: 5px;" onclick="Poll.sendAnswer("Programn2015","Answer1","Answer2")">Vote</a>
要单击文本为“投票”的链接,可以使用以下任一解决方案:
:css\u选择器
driver.find_element_by_css_selector("a.button.expanded.vote[onclick*='Answer1'][onclick*='Answer2']").click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.button.expanded.vote[onclick*='Answer1'][onclick*='Answer2']"))).click()
:xpath
driver.find_element_by_xpath("//a[@class='button expanded vote' and contains(.,'Vote')][contains(@onclick,'Answer1') and contains(@onclick,'Answer2')]").click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='button expanded vote' and contains(.,'Vote')][contains(@onclick,'Answer1') and contains(@onclick,'Answer2')]"))).click()
更新 诱导WebDriverWait使所需元素可单击,如下所示:
:css\u选择器
driver.find_element_by_css_selector("a.button.expanded.vote[onclick*='Answer1'][onclick*='Answer2']").click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.button.expanded.vote[onclick*='Answer1'][onclick*='Answer2']"))).click()
:xpath
driver.find_element_by_xpath("//a[@class='button expanded vote' and contains(.,'Vote')][contains(@onclick,'Answer1') and contains(@onclick,'Answer2')]").click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='button expanded vote' and contains(.,'Vote')][contains(@onclick,'Answer1') and contains(@onclick,'Answer2')]"))).click()
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
“我能做什么?”。。。您尝试了什么?您试图完成什么?发布相关的HTML或页面链接请与其他几个HTML共享,并带有其父标记或sibling标记。selenium.common.exceptions.NoSuchElementException:Message:无此类元素:无法定位元素:{“方法”:“css选择器”,“选择器”:“a.button.expanded.vote”[onclick*='Answer1'][onclick*='Answer2']>(会话信息:chrome=70.0.3538.67)(驱动程序信息:chromedriver=69.0.3497.106(857b28701ddf7bef0f14fa76416cf7ca786b411),platform=Linux 4.15.0-36-generic x86_64),如果我使用firefox编辑器复制xpath,我会得到“/*[@id=“soni”]/div/div/div/div/div[24]/div[2]/div/div/div]但是使用chrome.find通过xpath('/*[@id=“sondaggi”]/div/div[24]/div[2]/div/div[2]/div/div/div[1]/a')查找元素。单击()在page@MimmoBrescia签出我的更新答案并让我知道状态。嗨,我在两个“文件”中都出现此错误/usr/local/lib/python2.7/dist-packages/selenium-2.53.6-py2.7.egg/selenium/webdriver/support/wait.py”,第80行,直到引发TimeoutException(消息、屏幕、堆栈跟踪)selenium.common.exceptions.TimeoutException:message:“