我使用了明确的等待,我有警告:
org.openqa.selenium.WebDriverException:元素在点(36,72)处不可点击.其他元素将收到点击:...命令持续时间或超时:393毫秒
如果我使用Thread.sleep(2000)我没有收到任何警告.
@Test(dataProvider = "menuData")
public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.findElement(By.id("navigationPageButton")).click();
try {
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu)));
} catch (Exception e) {
System.out.println("Oh");
}
driver.findElement(By.cssSelector(btnMenu)).click();
Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用基于硒的Katalon Studio进行一些测试.在我的一个测试中,我必须在textarea内写.问题是我收到以下错误:
...Element MyElement is not clickable at point (x, y)... Other element would receive the click...
Run Code Online (Sandbox Code Playgroud)
事实上,我的元素位于其他可能隐藏它的diva中但是如何让click事件命中我的textarea?
在官方W3c webdirver文档中,明确指出位置策略是:
State Keyword
CSS selector "css selector"
Link text selector "link text"
Partial link text selector "partial link text"
Tag name "tag name"
XPath selector "xpath"
Run Code Online (Sandbox Code Playgroud)
但是,Selenium的电线协议允许:
class name
css selector
id
name
link text
partial link text
tag name
xpath
Run Code Online (Sandbox Code Playgroud)
在理论中,Selenium的文档已经过时,"真实"的故事在新的规范文档中.然而...
我在最新的Chrome自己的Webdriver上运行了一些测试,我可以确认这一点,name并且class name两者都有效; 但是,它们不符合规格.
我记得在Chromium问题上阅读他们只会实现官方的Webdriver规范.
现在:我知道通用答案,其中"规格并不总是100%遵循"等.但是,我想知道的是:
javascript selenium google-chrome chromium chrome-web-driver
我正在尝试抓取页面,但有时无法单击链接/按钮。
加载网页时,只要该框出现在网站上,“ loadingWhiteBox”将首先出现,然后在几秒钟后消失(但它将保留在HTML代码中),我无法单击链接,并且得到以下错误信息:
selenium.common.exceptions.ElementClickInterceptedException: Message:
Element <span class="taLnk ulBlueLinks"> is not clickable at point
(318.3000030517578,661.7999877929688) because another element <div
class="loadingWhiteBox"> obscures it
Run Code Online (Sandbox Code Playgroud)
有什么办法可以解决此问题?我已经尝试使用以下命令:
driver.is_element_present_by_css('div[class*="loadingWhiteBox"]')
Run Code Online (Sandbox Code Playgroud)
但是即使该元素不处于活动状态,它也存在。
我正在使用硒来抓取一些数据。
我点击的页面上有一个按钮说“custom_cols”。此按钮为我打开一个窗口,我可以在其中选择我的列。
这个新窗口有时需要一些时间才能打开(大约 5 秒)。所以为了处理这个我用过
WebDriverWait
Run Code Online (Sandbox Code Playgroud)
延迟为 20 秒。但有时它无法在新窗口中选择查找元素,即使该元素可见。这种情况只有十次发生一次,其余时间它都可以正常工作。
我也在其他地方使用了相同的功能(WebDriverWait),它按预期工作。我的意思是它会等到元素可见,然后在找到它的那一刻点击它。
我的问题是为什么即使我正在等待元素可见,新窗口上的元素也不可见。要在这里添加,我试图增加延迟时间,但我仍然偶尔会遇到该错误。
我的代码在这里
def wait_for_elem_xpath(self, delay = None, xpath = ""):
if delay is None:
delay = self.delay
try:
myElem = WebDriverWait(self.browser, delay).until(EC.presence_of_element_located((By.XPATH , xpath)))
except TimeoutException:
print ("xpath: Loading took too much time!")
return myElem
select_all_performance = '//*[@id="mks"]/body/div[7]/div[2]/div/div/div/div/div[2]/div/div[2]/div[2]/div/div[1]/div[1]/section/header/div'
self.wait_for_elem_xpath(xpath = select_all_performance).click()
Run Code Online (Sandbox Code Playgroud) python selenium web-scraping webdriverwait expected-condition
我试图单击“所有主题”和“所有状态”复选框,然后搜索结果。当我运行脚本时,会打开一个 1036x674 大小的 chrome 窗口。
如果我不理会窗口,我会收到元素点击拦截错误。如果我最小化或最大化窗口,我的脚本工作正常。
我正在使用 Selenium 3.141.0、chrome 76、chromedriver 76 和 python 3.6
chromedriver_path = r"C:\Users\path\to\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"
topics_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[1]/div[2]/span/label"
states_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[2]/div[2]/span/label"
browser.get(url)
time.sleep(30)
elem = browser.find_element_by_xpath(topics_xpath)
elem.click()
time.sleep(5)
elem = browser.find_element_by_xpath(states_xpath)
elem.click()
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
ElementClickInterceptedException:消息:元素点击被拦截:
元素 <label for="dnn_ctr81355_StateNetDB_ckBxAllTopics">...</label> 在点 (259, 665) 处不可点击。
其他元素将收到点击:
<label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">...</label>
(会话信息:chrome=76.0.3809.100)
将被单击的复选框位于我要单击的复选框的正下方。
selenium ×6
python ×3
java ×2
webdriver ×2
chromium ×1
exception ×1
javascript ×1
splinter ×1
web-scraping ×1
xpath ×1