I want to make a Python program with Selenium to fill out a form. Part of the process involves filling out a title. I used xpath to find the input associated with title, but then found out that it only works sometimes because its id is dynamic and keeps changing. Here is the html code associated with the title input box:
<div class='g5ia77ul buofh1pr d2edcug0 l9j0dhe7'>
<span class="m9osqain t5a262vz a8c37x1j b5fwa0m2 jagab5yi knj5qynh fo6rh5oj d2edcug0 ni8dbmo4 stjgntxs hzruof5a pmk7jnqg re5koujm ltmttdrg fgv6swy9 dd2scrzq ms05siws flx89l3n b7h9ocf4 g0qnabr5">Title</span>
<input dir="auto" aria-invalid="false" id="jsc_c_6" class="oajrlxb2 rq0escxv f1sip0of hidtqoto lzcic4wl g5ia77u1 gcieejh5 bn081pho humdl8nn izx4hr6d oo9gr5id qc3s4z1d knj5qynh fo6rh5oj osnr6wyh hv4rvrfc dati1w0a p0x8y401 k4urcfbm iu8raji3" type="text" value="">
</div>
Other boxes in the form have similar id, they all seem to start with "jsc_c_" like "jsc_c_a" or "jsc_c_8". Here is a picture of what part of the form looks like:
[][1
This is some of the code I have tried to select the title box:
titlePath = '//*[#id="jsc_c_6"]'
titleText = 'myTitle'
titleBox = driver.find_element_by_xpath(titlePath)
titleBox.send_keys(titleText)
I think that perhaps I could select the title input box by checking for the presence of the text "Title" in the box. However, I am not sure how this can be done. Any help or suggestions would be greatly appreciated.
Probably you can give it a try with
//span[text()='Title']/following-sibling::input
Related
buttonfinal = driver.find_element(
By.CSS_SELECTOR,
"button[class = '_2SQ6OPS1CO _3iCncfMaN4'").click()
I tried multiple solutions to click the button but still can't find the solution.
HTML CODE
<button type="submit" class="_2SQ6OPS1CO _3iCncfMaN4"><div class="">Registrati</div></button>
If you only have a single submit button, do this:
button_final = driver.find_element(By.CSS, 'button[type="submit"]')
button_final.click()
If you have multiple buttons with the same class, try this:
button_final = driver.find_element(By.Xpath, 'button[contains(text(), "Registratin")]')
button_final.click()
Tell me if this worked for you or not
I am trying to download two xls files from two dropdown boxes which are located in two similar data boxes.
The first data box:
<div id="contain" style="height: 400px" data-highcharts-chart="2">
…several containers…
<g class="highcharts-exporting-group" data-z-index="3</g>
The full path:
/html/body/div[2]/div/div[3]/div[1]/div/div[2]/div[1]/div/div[2]/div/div/svg/g[6]
The second data box:
<div id="containB2C" style="height: 400px" data-highcharts-chart="3">
…several containers…
<g class="highcharts-exporting-group" data-z-index="3</g>
The full path:
/html/body/div[2]/div/div[3]/div[1]/div/div[2]/div[2]/div/div[2]/div/div/svg/g[6]
I can click the first dropdown box with the code:
obj.FindElementByClass("highcharts-exporting-group").Click
and select the item:
obj.FindElementByXPath("//*[text()='Download XLS']").Click
But I cannot click the second drop down box in the second data box with similar code. Would appreciate any tips on how to do it.
As two dropdown boxes are similar, you could get a list or set of elements instead of a single element.
The below is just a demo and maybe has syntax error.(sorry I am not good at vba)
Dim titles As Object
Set titles = bot.findElementsByClass("highcharts-exporting-group")
For each item in titles
item.Click
Next item
I am writing a test script to click buttons that are dynamically inserted using ajax. However, after the script use the wait.element_to_be_clickable method, the final element turned out to be not able to be clicked.
The code looks something like this:
element1 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#element_1")))
element2 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#element_2")))
element3 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#element_3")))
element4 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#element_4")))
elements =[element1,element2,element3,element4]
for element in elements:
element.click()
submit_button = wait.until(EC..element_to_be_clickable((By.CSS_SELECTOR,"#element_5")))
submit_button.click()
The terminal jumped out an error message, saying that:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input id="fsSubmitButton3988487" class="fsSubmitButton" style="" type="submit" value="Submit Form"> is not clickable at point (509, 688). Other element would receive the click: <b>...</b>
I tried using the debugger to run through the script, and it works.
I also tried adding
time.sleep(2)
before the last line of code, and it also worked.
Why is the first method not working?
Element is located but Click is being intercepted, it happens when there pop up look for popup or some notification bar that is blocking the click...
I'm not a developer myself and even though html and css are kinda familiar to me, php and more advanced languages are not so please bear with me 😉
I want to have a simple html page (or php or whatever is necessary for this case) with 2 text fields and a button
What I want is to paste text into Field 1 and when I hit the Convert button, it will convert certain characters and show it in Field 2.
Example: I paste "I wanna go for a walk in the park" in Field 1. Hit Convert and Field 2 will show me "I w#nn# go for # w#lk in the p#rk"
(I know this is a silly example, but just so you can understand what I want to achieve).
I just need it to convert 1 single character at this point, so basically there's only 1 "variable".
Hope it makes and you guys can help me with it.
Thanks and stay safe!
Tiago 😊
html file
<input id="input_data" type="text">
<button id="convert">Convert</button>
<div>
<h1>Output</h1>
<p id="output"></p>
</div>
<script type="text/javascript">
document.getElementById("convert").onclick = function(){
var input = document.getElementById("input_data").value;
// your choice
var convert_from = "a";
var convert_to = "o";
var finalString = (input.split(convert_from.toUpperCase()).join(convert_to.toUpperCase())).split(convert_from).join(convert_to);
document.getElementById("output").textContent = finalString;
copyToClipboard(finalString);
}
// You can copy some text to clipboard only by selecting an element
function copyToClipboard(content){
// Create a textarea
var textHolder = document.createElement('textarea');
// Assign the value
textHolder.value = content;
// Appent the textarea to body
document.body.appendChild(textHolder);
// "Focus the action" on the textHolder
textHolder.select();
textHolder.setSelectionRange(0, 99999); /*For mobile devices*/
// Copy the content from selected element
document.execCommand('copy');
// Remove the textarea from body
document.body.removeChild(textHolder);
}
</script>
I hope it helps! ^_&
I have this code using Quasar/VueJS. What I want to do is update the dropdown text label (keyDropDownLabel) based on the selected <q-item-label>.
So in this example below, I want the newLabelGoesHere part to be Key 1/2/3, depending on which was clicked.
<q-btn-dropdown stretch flat :label="keyDropDownLabel">
<q-list>
<q-item v-for="n in 3" :key="`x.${n}`" clickable v-close-popup tabindex="0">
<q-item-section #click="keyDropDownLabel = 'newLabelGoesHere'">
<q-item-label>Key {{ n }}</q-item-label>
<q-item-label caption>1234567890</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-btn-dropdown>
Anyone help please??
Just modify the q-item-section click method like below:
<q-item-section #click="keyDropDownLabel('Key'+n)">