我有此代码
"Answer1","Answer2"
我该怎么办?页面上还有其他具有相同类的按钮,等等,唯一的变量是
import pickle
a = [1,2,3]
b = [4,5,6]
with open("pickle1.dat", 'wb') as f:
pickle.dump(a, f)
pickle.dump(b, f)
c = None
d = None
with open("pickle1.dat", 'rb') as f:
c = pickle.load(f)
d = pickle.load(f)
print(c)
print(d)
答案 0 :(得分:0)
要单击带有投票的文本的链接,可以使用以下任一解决方案:
css_selector
:
driver.find_element_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 以使所需的元素可点击,如下所示:
css_selector
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.button.expanded.vote[onclick*='Answer1'][onclick*='Answer2']"))).click()
xpath
:
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