无法打开 link 或单击文本按钮转到带有 selenium 和 python 的网站上的 reletad 区域
Inability to open the link or click on the text button to go to the reletad area on the website with selenium and python
网站的javascript代码:
div class="display-actions">==[=12=]
<a class="show-all" href="/acount/previous_orders" data-yslinktracking="mainpage:previous_orders:all_previous_orders">All Previous Orders</a>
朋友们您好,网站上有个文字叫做“All Previous Orders”。我想自动点击它,但我做不到。
当我将鼠标悬停在网站上的此文本(所有以前的订单)上时,https://www.websitename.com/acount/previous_orders 出现在页面的底角。我需要找到并单击 link 或者可能有其他解决方案来单击此文本。
看看这是否有效:-
previousOrder = driver.find_element_by_xpath("//a[text()='All Previous Orders']")
driver.execute_script("arguments[0].scrollIntoView(true);",previousOrder)
previousOrder.click()
如果你更喜欢 CSS 而不是 XPATH,你可以使用下面的 css_selector :
a[href='/acount/previous_orders']
然后像这样点击它:
ActionChains(driver).move_to_element(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href='/acount/previous_orders']")))
).click().perform()
进口:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
代码有效:
driver.execute_script("window.scrollTo(0, 300)") #move the area
order= driver.find_element_by_xpath("//a[text()='All Previous Orders']")
order.click()
网站的javascript代码:
div class="display-actions">==[=12=]
<a class="show-all" href="/acount/previous_orders" data-yslinktracking="mainpage:previous_orders:all_previous_orders">All Previous Orders</a>
朋友们您好,网站上有个文字叫做“All Previous Orders”。我想自动点击它,但我做不到。 当我将鼠标悬停在网站上的此文本(所有以前的订单)上时,https://www.websitename.com/acount/previous_orders 出现在页面的底角。我需要找到并单击 link 或者可能有其他解决方案来单击此文本。
看看这是否有效:-
previousOrder = driver.find_element_by_xpath("//a[text()='All Previous Orders']")
driver.execute_script("arguments[0].scrollIntoView(true);",previousOrder)
previousOrder.click()
如果你更喜欢 CSS 而不是 XPATH,你可以使用下面的 css_selector :
a[href='/acount/previous_orders']
然后像这样点击它:
ActionChains(driver).move_to_element(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href='/acount/previous_orders']")))
).click().perform()
进口:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
代码有效:
driver.execute_script("window.scrollTo(0, 300)") #move the area
order= driver.find_element_by_xpath("//a[text()='All Previous Orders']")
order.click()