我正在尝试填写自动填充的邮政编码/城镇表格。即使您一次输入了整个邮政编码/城镇,您仍然必须验证自动完成搜索(就在输入下方)。我不会为每次尝试都输入整个错误消息,否则我的帖子会太长(我为每个帖子都输入了一个数字尝试和->显示相应的结果。
输入:
ville = 31000 Toulouse
geo = driver.find_element_by_id("location_p")
geo.send_keys(ville)
从这里开始问题: 这是制作pbs的代码:
<li data-region="16" data-dpt-code="31" class="selected">
<span class="city" title="Toulouse">Toulouse</span>
<span class="zipcode">31000</span>
</li>
1。
validate = driver.find_element_by_xpath("//li[@class='selected'][contains(.,'data-dpt-code')]")
validate.click()
->无法找到元素
2。
validate = driver.find_element_by_css_selector("li.selected")
validate.click()
-> <exception str() failed>
但是
validate = driver.find_element_by_css_selector("li.selected")
assertTrue(validate_is_displayed() and validate_is_enabled())
validate.click()
->无法找到元素
3。 从这个How to handle autocomplete list in webdriver?,我尝试过:
geo.send_keys(Keys.TAB)
geo.send_keys(Keys.TAB)
geo.send_keys(Keys.DOWN)
->没有错误,但邮政编码/城镇未通过验证
来自Selenium Python - select from autosuggest dropdown的4.,已尝试
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@class='selected']/span[@class='city][contains(.,'Toulouse')]"
->同上为3
5。从Selenium in Python How use a If - else code if an element is not present,我尝试过:
elem = driver.find_element_by_xpath('//*[@class="selected"][contains(.,"data-dpt-code")]')
valid = driver.find_element_by_xpath('//span[@class="city"][contains(.,"Toulouse")]')
if valid.is_displayed():
elem.click()
-> selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (309.5, 9.75). Other element would receive the click: <section class="content-center clearfix"></section>
我需要你的帮助!!提前感谢
答案 0 :(得分:0)
从此错误看来元素不在屏幕上:
selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (309.5, 9.75). Other element would receive the click: <section class="content-center clearfix"></section>
在单击之前,您是否尝试过使用动作链并移至该元素?
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(your_element).click().perform()
答案 1 :(得分:0)
使用Webdriver等待尝试单击li
元素
wait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//li[@class="selected" and contains(., "Toulouse")]'))
).click()
还要尝试使用其他条件,例如presence_of_element_located
或visibility_of_element_located
答案 2 :(得分:0)
我终于不得不使用chrome和chromedriver:
WebDriverWait(driver,
10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,".location-list >
li:nth-child(1)"))).click()