Friends facing challenges again in following scenarios using Python with Selenium web driver:-
Click event not happening on clicking the link name as "Area Rank Web".
HTML Code for MSTR Report is as follows:-
<td class="mstrLargeIconViewItemText" rowspan="1" colspan="1" cx="[2,1,0,5,1,6,7]" cxid="folderAllModes_cmm" oid="600E4BA841AC84797221F7BB5262C3E0" oty="55"><a title="Run Document" class="mstrLargeIconViewItemLink" onclick="return submitLink(this, event);" href="Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0¤tViewMedia=1&documentID=600E4BA841AC84797221F7BB5262C3E0" runasexpress="1" alt="Run Document"></a><div class="mstrLargeIconViewItemName"><span sty="nm"><a title="Area Rank Web" class="mstrLink" onclick="return submitLink(this, event);" href="Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0¤tViewMedia=1&documentID=600E4BA841AC84797221F7BB5262C3E0" runasexpress="1">Area Rank Web</a></span></div><div class="mstrLargeIconViewItemOwner"><label>Owner:</label><span><div title="Administrator" class="owner">Administrator</div></span></div><div class="mstrLargeIconViewItemModified"><label>Modified:</label><span><div timestamp="1525148536000">5/1/18 4:22:16 AM</div></span></div><div class="mstrLargeIconViewItemDescription"></div><div></div><div class="mstrLargeIconViewItemActions"><span><a class="mstrLink" onclick="if (!mstrFolderActions.checkACL(this, event, '600E4BA841AC84797221F7BB5262C3E0', 55)) return; return submitLink(this, event);" href="Main.aspx?evt=3032&src=Main.aspx.3032&objectType_3032=55&objectID_3032=600E4BA841AC84797221F7BB5262C3E0" ty="sub">Subscriptions</a></span></div></td>
I tried following ways but not getting success:
#driver.find_element_by_xpath(".//*[title='Area Rank Web']").click();
#driver.find_elements_by_class_name (("mstrLargeIconViewItemName") and contains(.,'Area Rank Web')).click()
#driver.find_element_by_id("600E4BA841AC84797221F7BB5262C3E0").click()
#driver.find_element_by_css_selector("600E4BA841AC84797221F7BB5262C3E0").click()
#WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='mstrLargeIconViewItemText']/span[#class='mstrIcon-lg' and contains(.,'Area Rank Web')]"))).click()
2.
There is a block having two values as:- AREA, DISTRICT. You can select more than value and then click on arrow button which moves selected content to the right side of block and then click on submit button
HTML code:
<div title="AREA" class="mstrListBlockItemSelected" style="margin-top: 0px;"><div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">DSI</div></div>
<div title="DISTRICT" class="mstrListBlockItem" style="margin-top: 0px;"><div class="mstrBGIcon_ae mstrListBlockItemName" style="background-position: 2px 50%; padding-left: 23px;">ONC</div></div>
Tried following ways but click event is not happening
Can you try link_text/ partial_link_text instead?
driver.find_element_by_link_text('Area Rank Web').click()
OR
driver.find_element_by_partial_link_text('Area Rank Web').click()
Also, try having an explicit wait before you click on the link.
WebDriverWait(self.driver, 10).until(expected_conditions.element_to_be_clickable(
(By.LINK_TEXT, 'Area Rank Web')
))
if all the above fails, use execute_script method to invoke a click event on the link
link = driver.find_element_by_link_text('Area Rank Web')
driver.execute_script('arguments[0].click();', link)
Related
I am trying to have selenium click on the next page button at this site after clicking the submit button and getting pages of results: https://elibrary.ferc.gov/eLibrary/search
I have tried countless ways to have selenium click on this button. The html code for the next page button on the results page is here:
<button class="mat-paginator-navigation-next mat-icon-button" mat-icon-button="" type="button" aria-describedby="cdk-describedby-message-8" cdk-describedby-host="" aria-label="Next page" style="touch-action: none; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"><span class="mat-button-wrapper"><svg class="mat-paginator-icon" focusable="false" viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button>
I've tried the following:
link = driver.find_element_by_xpath('//*[#id="rsltToolbar"]/mat-paginator/div/div/div[2]/button[2]')
link.click()
But the code does not work. Hopefully this is the button that needs to be clicked! I've tried by css selector, class_name, by javascript etc. to no avail. Any help much appreciated.
link = driver.find_element_by_classname("mat-paginator-navigation-next")
should work fine
# (tested in js console with)
document.querySelector(".mat-paginator-navigation-next").click()
you might have to just add a delay (ie its probably not clickable initially(or clicking it too soon just does nothing)) I think you can wait for it to be clickable somehow
driver.findElement(By.id("submit")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[#id='rsltToolbar']/mat-paginator/div/div/div[2]/button[2]")).click();
XPath you have tried is working just need to add delay after you click "Search" on page"https://elibrary.ferc.gov/eLibrary/search"
Trying to press a button, but nothing happens. There are no errors when clicking, the element itself is located. Element is visible.
There is a my code:
verify = self.driver.find_element_by_xpath('//span[text()="Resend email"]')
ActionChains(self.driver).move_to_element(verify).click(verify).perform()
HTML:
<div class="Box-root Box-hideIfEmpty" style="pointer-events: auto;"><button class="UnstyledLink ButtonLink Flex-flex" type="button"><div class="Box-root Flex-flex Flex-alignItems--baseline Flex-direction--row" style="position: relative;"><div class="TextAligner Box-root" style="line-height: 20px; font-size: 14px; flex: 0 0 auto;"></div>
<div class="Box-root Flex-flex Flex-alignItems--baseline Flex-direction--row Flex-justifyContent--flexStart" style="line-height: 0; flex: 1 1 auto;"><span class="ButtonLink-label Text-color--blue Text-fontSize--14 Text-fontWeight--medium Text-lineHeight--20 Text-numericSpacing--proportional Text-typeface--base Text-wrap--noWrap Text-display--block" style="margin-top: -1px;">
<span>Resend email</span></span></div></div></button></div></div></div>
UPD: Solved the problem. If u have same issue try to change browser profile / launch with default options
I was able to click on it... Not sure what is the problem on your side...
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox(executable_path=r'D:\geckodriver.exe')
driver.get('https://stripe.com/')
#click on Sign-in
driver.find_element_by_xpath('/html/body/header/div[1]/nav/ul/li[3]/a[2]/span').click()
#send email
driver.find_element_by_xpath('//*[#id="email"]').send_keys("abc#gmail.com")
#send password
driver.find_element_by_xpath('//*[#id="old-password"]').send_keys("akldjfkajdf")
#click on continue
driver.find_element_by_xpath('/html/body/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div[2]/div/div/div[2]/div/div/div/div[2]/form/div/div/div/div[4]/div/div/div/div/div/div[1]/button/div/div[2]/span').click()
#click on skip for now
driver.find_element_by_xpath('/html/body/div/div/div[2]/div[3]/div/div/div/a/span').click()
#click on verify you email
driver.find_element_by_xpath('/html/body/div[2]/span/div/div/div[1]/div/div[2]/div[2]/div/span/div/div[4]/div[2]/div/div/div/div/div[1]/div/div/div/div[2]/div[2]/span/span').click()
#click on resend email
driver.find_element_by_xpath('/html/body/div[2]/span/div/div/div[1]/div/div[2]/div[2]/div/span/div/div[4]/div[2]/div/div/div/div[2]/div[2]/div/div/div/div/div[2]/button/div/div[2]/span/span').click()
I am trying to make click for this element,
but getting error like
>> ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (271, 705)
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[#action="/battle/"]/div/input[2]')))
element.click();
This is not helping also getting timeoutexception. I think element kinda covered
with:
[driver.find_element_by_xpath('//[#action="/battle/"]/div/input[2]').click()]
<form action="/battle/" method="post" name="4416" id="4416" onsubmit="get('/battle/', '', this); disableSubmitButton(this); return false;"><div class="battleView" style="float:left; width:65%;"><h3 class="heading-maroon no-right-border-rad margin-right-2">Attack Results</h3><table cellpadding="0" cellspacing="0" style="width: 80%; text-align: center; margin: 0 auto;">
...
</tbody></table><input type="hidden" class="button-maroon button-small" name="action" value="attack">
<input type="submit" class="button-maroon button-small" value=" Attack .. "></div>
</form>
It looks like it's showing the X/Y coordinates (271,705) in the error message. I'd try a macro product like AppRobotic to look up the X/Y coordinates of elements that you have issues finding with XPATH, moving the mouse, or sending keystroke TABS, and clicking it. A simple example:
import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
from selenium import webdriver
# navigate to Yahoo
driver = webdriver.Firefox()
driver.get('https://www.yahoo.com')
# sleep 1 second
x.Wait(1000)
link = driver.find_element_by_link_text('Mail')
if len(link) > 0
link[0].click()
else
x.Wait(3000)
# use UI Item Explorer to get X,Y coordinates of Mail box
x.MoveCursor(271,705)
# click inside Search box
x.MouseLeftClick
# could also try tabbing over and pressing Enter
x.Type("{TAB}")
x.Type("{ENTER}")
Another idea is to try scrolling to the element with Selenium first:
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_xpath('//[#action="/battle/"]/div/input[2]')
actionchains = ActionChains(driver)
actionchains.move_to_element(element).perform()
On a non-public webpage I have the following html content:
<span click.delegate="placeCurrentInjection()" style="display:flex" class="au-target" au-target-id="611">
<ui-button glyph="glyph-iclamp" small="" primary="" disabled.bind="currentPlaceDisabled"
style="width: auto; max-width: 20em;" class="au-target ui-small ui-button primary" au-target-id="612" role="button" data-value="">
<span class="ui-indicator"><!--anchor--></span>
<ui-glyph glyph.bind="glyph" class="au-target ui-icon ui-btn-icon glyph-iclamp" au-target-id="36"><!--view-->
<svg>
<use tabindex="-1" x="0" y="0" class="au-target"
au-target-id="11" xlink:href="#glyph-iclamp"></use>
</svg>
<!--anchor--></ui-glyph><!--anchor-->
<!--anchor-->
<span class="ui-label">Place current injection<!--slot--></span>
<!--anchor--></ui-button> </span>
which shows a button like follows:
and I want to click on that button, using the following code in selenium 3.8.0:
elem = WebDriverWait(self.webdriver, time_sec).\
until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(), 'Place current injection')]")))
elem.click()
However, I get the following error:
E ElementClickInterceptedException: Message: Element <span class="ui-label"> is not clickable at point (782.2999877929688,156.03334045410156) because another element <ui-button class="au-target ui-small ui-button primary"> obscures it
Despite the fact the actual text is not obscured in any way and I can click on it - how to fix this issue?
The element you located is just the text on a label of the button. You need to click on the button itself, which is actually the element from the error message you received. The button is the parent element so you can use the text to locate it by moving to the parent
(By.XPATH, "//span[contains(text(), 'Place current injection')]/..")
I am writing a program to gather data from a website, however at some point in the program I need to enter an email and password into text boxes. The route I am attempting to go is to use driver.execute_script to change the underlying HTML, however I am having difficulty connecting that command with the XPATH value that I use to find the element. I know there are a few threads on here that deal with similar issues, however I have been completely unable to find one that uses XPATH. Any help would be greatly appreciated as I am totally stuck here.
Below is the line of HTML that I am attempting to change, as well as the XPATH value associated with the text box.
XPATH Value
/html/body/center/div[4]/table[2]/tbody/tr/td[4]/table[1]/tbody/tr[2]/td/table/tbody/tr[7]/td[2]/font
HTML:
<input onclick="if (this.value == 'Enter Your Name') this.value='';" onchange="if (this.value == 'Enter Your Name') this.value='';" name="name" type="text" value="Enter Your Name" style="padding-top: 2px; padding-bottom: 6px; padding-left: 4px; padding-right: 4px; width:120px; height:15px; font-size:13px; color: #000000; font-family:Trebuchet MS; background:#FFFFFF; border:1px solid #000000;">
I am attempting to replace value = "Enter Your Name" with value = "Andrew" - or any other name for that matter. Thank you very much for any and all advice, and please let me know there is any additional data / info that is required.
Send_Keys scripts:
name = driver.find_element_by_xpath('//body/center/form/span/table/tbody/tr/td[1]/input')
name.clear()
name.send_keys("Andrew")
Your <input> tag is contained within an <iframe>, so you'll need to switch the context to the <iframe> first:
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
Now that you're "inside" the <iframe>, your send_keys script should work:
name = driver.find_element_by_xpath('//body/center/form/span/table/tbody/tr/td[1]/input')
name.clear()
name.send_keys("Andrew")
Lastly, here's how to switch back to the default content (out of the <iframe>):
driver.switch_to.default_content()