[英]Using Selenium in Python to access hidden table in JavaScript website
I'm trying to use Selenium webdriver with Python to open an HTML link that seems to be hidden within a JavaScript table, which is in an iframe. 我正在尝试将Selenium Webdriver与Python一起使用,以打开似乎隐藏在iframe中JavaScript表中的HTML链接。 I know the last 2 lines are not currently doing very much. 我知道最后2行目前做得并不多。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Open MasterControl
url = *****
driver = webdriver.Chrome(executable_path = r'C:\Users\jmiller\Desktop\MasterControl Scraping\chromedriver')
driver.get(url)
# Login using my credentials
username = driver.find_element_by_id('userid')
password = driver.find_element_by_name('password')
username.send_keys('*****')
password.send_keys('*****')
submitButton = driver.find_element_by_id('MCP_BUTTON_40')
submitButton.click()
# Search for assets
asset = driver.find_element_by_id('strSearchPortal')
asset.send_keys('****')
goButton = driver.find_element_by_xpath("//input[@type = 'submit']")
goButton.click()
# Open asset form
driver.switch_to.frame('myframe')
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//div[@id = 'folder_Forms']/div[@id = 'row2']/div[@id = 'column_i.title_nm']/a")))
element.click()
'folder_Forms' seems to be where I'm getting lost. 'folder_Forms'似乎是我迷路的地方。 The link I want to click his hidden until you click on the "Forms" icon on the website. 我要单击他隐藏的链接,直到您单击网站上的“表单”图标。 Do I have to execute the JavaScript "toggleFolder" function? 我必须执行JavaScript“ toggleFolder”功能吗? Any help is greatly appreciated. 任何帮助是极大的赞赏。 Let me know if more info would be helpful - I'm trying to avoid copying over the entire site. 让我知道更多信息是否有帮助-我正尝试避免在整个网站上进行复制。
<div id="folder_Forms" class="listDataTable" style="margin-left: 10px;width: 99%;">
<span style="cursor:pointer" onclick="toggleFolder('image_Forms','group_Forms');">
<img src="*****" id="image_Forms" title="Hide Content">
Forms
</span>
<span style="font-weight:lighter;font-size:11px;color:#666666; " onclick="toggleFolder('image_Forms','group_Forms');">(3 records)
</span>
<span>
</span>
</div>
尝试使用execute_script
执行toogleFolder
,您会看到它是否有帮助
driver.execute_script("toggleFolder('image_Forms','group_Forms');")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.