Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python selenium中滚动到特定元素_Python_Selenium_Selenium Webdriver - Fatal编程技术网

在python selenium中滚动到特定元素

在python selenium中滚动到特定元素,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我试图向下滚动到python中的特定元素,但它不起作用。有任何改进建议 Loc_Hours =self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]") self.driver.execute_script("return arguments[0].scrollIntoView();", Loc_Hours) Lo

我试图向下滚动到python中的特定元素,但它不起作用。有任何改进建议

Loc_Hours =self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]")
self.driver.execute_script("return arguments[0].scrollIntoView();", Loc_Hours)
Loc_Hours.text()
self.driver.execute_script("window.scrollBy(0, -150);")

你能试试这个吗

from selenium.webdriver.common.action_chains import ActionChains

Loc_Hours = self.driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[1]/div[2]/div[1]/p[1]")
ActionChains(self.driver).move_to_element(Loc_Hours)).perform()

这对我来说是成功的!如果你有疑问就试试这个

print(Loc_Hours.get_attribute('textContent'))
这应该起作用:

driver.execute_script("arguments[0].scrollIntoView()", Loc_Hours);

<代码> > LojthTime.Tr[()/代码>??我希望你尝试了这个“DeBangJub”。Looph在页面的中间,我需要向下滚动到那个区域并得到文本。试试<代码>打印(LoopHith.GETSyAtgage(‘TrimeCyfage’))< /C> >安德松真棒!YouthOffice小时在页面的中间,我需要向下滚动到该区域并获取文本。这就是我的疑问@你试过我的答案了吗?请告诉我这是否适用于滚动?我收到ElementNotVisibleException@Nihal
Loc\u Hours=self.driver.通过xpath(“/html[1]/body[1]/div[1]/div[2]/div[1]/div[5]/div[1]/div[1]/div[2]/div[1]/p[1]”来查找元素?因为我知道
ActionChains(self.driver)。移动到元素(Loc\u Hours))。perform()
会让你从评论中得到答案。好。你应该把它作为你的答案,并接受它。对于其他有相同问题的人来说,不,它不起作用,首先我只使用了@Alichino这个方法,然后我因为找到一个解决方案而感到压力,来到这里并找到了一个解决方案